-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Connection pool hangs if authentication fails #141
Comments
I'd be happy to review a PR for this, but I don't think I'll be able to work on this myself in the near future. |
I've spent a bit of time looking into this while debugging some TLS connection issues. It is decidedly not a simple fix, unfortunately. There are a few things that I've been doing to make life a little bit easier, however:
The touchpoint for the issues is at Lines 199 to 225 in 5737736
ManageConnection impl to make the connection, and (in the case of an error) keeps trying until it gets one successfully or the pool's connection timeout expires.
The right behavior in the general case is to delay returning any error until the timeout, but it would be great if there were a way to identify particular classes of errors that shouldn't wait for the timeout. It seems like that would require cooperation from the As a side note @djc or anyone else looking more deeply, this call stack is Lines 138 to 139 in 5737736
|
That sounds sensible. Want to propose a PR?
Might be worth an issue against tokio-postgres? I would definitely be open to adding an |
Happy to work something up. Since the waiter is stored in Line 67 in 5737736
with a call to a new method on impl<M: ManageConnection> PoolInternals<M> {
fn forward_error(&self, err: M::Error) {
let mut locked = self.internals.lock();
while let Some(waiter) = locked.waiters.pop_front() {
match waiter.send(Err(err)) {
Ok(_) => return,
Err(e) => err = e,
}
}
self.statics.error_sink.sink(e);
}
}
It looks like it has been discussed a few times (sfackler/rust-postgres#571, sfackler/rust-postgres#583, sfackler/rust-postgres#790), though usually in a different context. There's even another project that is trying to do exactly the same thing: https://github.com/palfrey/wait-for-db/blob/c3fb9dbad94f06f91f83d6ef9e4af0b93ef64083/src/pg.rs#L34-L49 In at least one case a PR was merged that exposed a limited interface to the error kind (sfackler/rust-postgres#739) so it's reasonable to think a similar PR would be well received. |
Yeah, the |
Hmm, it's not so easy, I guess. The above strategy works, but only if the user has configured Line 142 in 03f95c9
Line 216 in 03f95c9
After a quick review I don't immediately see a great way to get these to line up that doesn't feel like a hack (i.e. make the outer one "a little bit longer" or some such). The outer timeout can't really be removed, since we're relying on that in the face of pool contention. The inner timeout in the context of the retry loop looks locally correct, and it's hard to picture what would need to change really. I'll go ahead and submit a PR to bubble up the error for the case of a pool configured with |
This ensures that an active waiter will be notified of a connection failure before we resort to sending it to the sink. Contributes to djc#141.
This ensures that an active waiter will be notified of a connection failure before we resort to sending it to the sink. Contributes to #141.
…tation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
…tation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
…tation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
…tation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
…tation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
…mplementation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
…tation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
…tation. The problem is, `bb8` swallows all error messages as retry timeouts. See djc/bb8#141
When using a connection pool with tokio_postgres, the connection hangs until a TimedOut error is returned if the password is incorrect. This behaviour is undesirable and should just result in authentication failure.
To re-produce, simply try connect to any database using an incorrect password and the connection will hang until it times out.
The text was updated successfully, but these errors were encountered: