When a process terminates then tokio-postgres closes the connection. PostgreSQL reports: DEBUG: unexpected EOF on client connection.
I started looking into this because I got a similar message from pgbouncer. When directly connecting to PostgreSQL and with DEBUG1 logging turned on this behaviour can also be seen, so it's not related to pgbouncer.
When I add drop(client); as a final statement in the main function then the unexpected EOF often goes away, but sometimes it needs a bit more time after dropping the client (e.g. by adding a very short sleep). My hypothesis is that the message used to signal the server that the connection will be closed hasn't been (fully) sent when the process terminates. Maybe something additional needs to happen when a connection is dropped to ensure the last bytes have also been sent.
The issue can be reproduced using the first example from the tokio-postges docs (top example from tokio-postgres/src/lib.rs). I've tried connecting using a unix domain sockets and TCP and I could reproduce this in both cases. I've configured PostgreSQL logging with log_min_messages = 'DEBUG1' to be able to see this message. I'm using PostgreSQL 14 and FreeBSD 13.1.
When a process terminates then tokio-postgres closes the connection. PostgreSQL reports:
DEBUG: unexpected EOF on client connection
.I started looking into this because I got a similar message from pgbouncer. When directly connecting to PostgreSQL and with
DEBUG1
logging turned on this behaviour can also be seen, so it's not related to pgbouncer.When I add
drop(client);
as a final statement in themain
function then the unexpected EOF often goes away, but sometimes it needs a bit more time after dropping the client (e.g. by adding a very short sleep). My hypothesis is that the message used to signal the server that the connection will be closed hasn't been (fully) sent when the process terminates. Maybe something additional needs to happen when a connection is dropped to ensure the last bytes have also been sent.The issue can be reproduced using the first example from the tokio-postges docs (top example from
tokio-postgres/src/lib.rs
). I've tried connecting using a unix domain sockets and TCP and I could reproduce this in both cases. I've configured PostgreSQL logging withlog_min_messages = 'DEBUG1'
to be able to see this message. I'm using PostgreSQL 14 and FreeBSD 13.1.