Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgresConnection.authenticate responds with uncleanShutdown error when wrong credentials are passed #160

Open
avolokhov opened this issue May 18, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@avolokhov
Copy link

Describe the bug

When I mess up my credentials and try to send a random gibberish as a password, the error I get in return is obscure and not very helpful. I would expect PostgresConnection.authenticate to fail with a clean auth failed error, but I get PostgresError.protocol("Unexpected connection close") instead.

To Reproduce

  1. set up a working postgres instance
  2. connect to it via PostgresConnection.connect().authenticate() using a random gibberish for the password
  3. check the error message

Expected behavior

I'd expect a clean auth failed error.

Environment

vapor 4.45.2
postgres-nio 1.5.2

@avolokhov avolokhov added the bug Something isn't working label May 18, 2021
@avolokhov
Copy link
Author

avolokhov commented May 18, 2021

When I debug it locally, I see we're hitting this error case in ConnectionStateMachine#186:

   mutating func closed() -> ConnectionAction {
        switch self.state {
        case .initialized:
            preconditionFailure("How can a connection be closed, if it was never connected.")
        case .closed:
            preconditionFailure("How can a connection be closed, if it is already closed.")
        case .authenticated,
             .sslRequestSent,
             .sslNegotiated,
             .sslHandlerAdded,
             .waitingToStartAuthentication,
             .authenticating,
             .readyForQuery,
             .extendedQuery,
             .prepareStatement,
             .closeCommand:
            return self.errorHappened(.uncleanShutdown) // <----- Here
        case .error, .closing:
            self.state = .closed
            self.quiescingState = .notQuiescing
            return .fireChannelInactive
        case .modifying:
            preconditionFailure("Invalid state")
        }
    }

In debugger I see self.state has an information that we're currently in authenticating/passwordAuthenticationSent.
I think if we were able to bubble this state up and log/throw it appropriately, this would be a huge help in investigating such problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant