-
Notifications
You must be signed in to change notification settings - Fork 843
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
Session reset callbacks cannot be used with the background reader #1673
Comments
I think also the background reader broke |
I've merged #1670. Will that also resolve this? |
Unfortunately not. The background reader is still there, so other entities that will try to use the underlying I understand the need for the background reader, and the issue that it solves (deadlocks due to full write buffers on both sides of a connection) - I just don't have a good solution regarding how to stop the background reader when it is not used (i.e. after In our project we have removed the session reset callback and rely on the health checks that |
If I understand correctly, the background reader will only be activated if there was a slow write. But then the background goroutine will continue running even after In theory The only other option for stopping it seems to be to induce a read via I suppose we could introduce some method(s) to expose the state of the background reader. If it is running we can consider the connection alive. Not too excited about exposing internal state though. Don't want to get locked into this particular implementation of write deadlock prevention. |
I agree with this assessment -
Indeed, we could
That's fair. Unless someone comes up with a smarter solution regarding how we could manage the lifetime of the background reader, I think the only action point for now is to ensure that the background reader is stopped in |
This provides a way to ensure it is safe to directly read or write to the underlying net.Conn. #1673
@adriansmares Please take a look at a potential solution in PR #1679. |
This provides a way to ensure it is safe to directly read or write to the underlying net.Conn. #1673
I believe this should be resolved in v5.4.2. |
Describe the bug
The background reader introduced in #1629 maintains the FD lock over the underlying
net.Conn
/ file descriptor. As such, because the background reader keeps the file descriptor lock, the session reset callback cannot do a low level file descriptorRead
in order to check if the connection has been gracefully ended or not.To Reproduce
We use this implementation of a session reset fallback.
Because the background reader is still operating in the background after a connection has been used for a query at least once, the session reset fallback basically deadlocks while waiting for the background read to end (which it never does, since the background reader has no deadline).
Expected behavior
The session reset fallback should have access to the underlying
net.Conn
bidirectionally.Actual behavior
The background reader keeps the file descriptor of the
net.Conn
locked in the background.Version
$ go version
->go version go1.20.5 darwin/arm64
$ psql --no-psqlrc --tuples-only -c 'select version()'
->PostgreSQL 14.8 (Debian 14.8-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
$ grep 'github.com/jackc/pgx/v[0-9]' go.mod
->v5.4.1
Additional context
Perhaps the
*PgConn
should have some form of 'peek' method that allows the session reset callback to check the error of the last unreadRead
call ? It is racy, but we could check forio.EOF
there and returndriver.ErrBadConn
.Another possible solution is to make the
exitPotentialWriteReadDeadlock
set a deadline on the connection and read the error perhaps. This is racy again.A non racy solution would be to allow
*PgConn
users to stop the background reader and wait for it close, but I am not sure if interrupting theRead
intentionally via deadlines is the best way of achieving this.The text was updated successfully, but these errors were encountered: