Conversation
There was a problem hiding this comment.
LGTM! Thanks a lot for looking into this. This seems to be a case that we overlooked, and more checks can't hurt.
Like we've seen earlier, it seems the client drops the connection to then ask for the password, and Postgres still tries to answer twice the client, first with some bytes then with some error message, but nobody is there to listen anymore.
It seems b'R\x00\x00\x00\x08\x00\x00\x00\x03' means something about authentication (https://www.postgresql.org/docs/current/protocol-message-formats.html), and that a password is required.
I suppose it goes this way:
- if
-Wis included, the client knows it needs to prompt for the password first, then try to connect. - If it's not, it will still try to connect to Postgres first, but Postgres will respond that it needs a password first. So the client drops the connection, prompt a password, save it in memory then re-request a connection, this time including the password, and the server accepts it.
I think we were not covering the case where the server would still try to send a message after sending what could look like "a termination message" for the client.
So it's a go for me, maybe we can have @whummer opinion on this as well.
whummer
left a comment
There was a problem hiding this comment.
Great insights, kudos for sharing the detailed analysis! LGTM 👍
Background
Recently, we got notified about a customer that the RDS instance was not reachable, with the logs in LocalStack:
I was able to reproduce this issue locally, by running the following
psqlcommand for a RDS-instance created in LocalStack:-Woption. When this option is included, the password prompt is shown instantly, and the connection succeeds-Woption is omitted, thepsqlstill shows (a slightly different) password prompt, but before we can see some messages being send to the proxy:self.redirect_connis None, and the connection to the proxy is broken with the error message from above. Somewhere in between the connection seems to be reset here.Solution
In order to not terminate the proxy, we need a check in the
process_inbound_packetthat ensures theself.redirect_connis still available.