Repository navigation
Fix unhandled rejections when Cloudflare sockets close - #1251
advitrocks9 wants to merge 2 commits into
Conversation
|
Thanks for this fix. We backported the One compatibility finding: we tried the Sharing this as a PGlite-backed test compatibility observation; we have not established that the same behavior occurs against a regular PostgreSQL server. Our regression executes |
|
Thanks, good catch. b0922e4 closes only the write side after Terminate, so PGlite closes too. |
|
Thanks! This is part of v4 (06cf284), so I am closing it here. The changelog has the details: https://github.com/porsager/postgres/blob/master/CHANGELOG.md |
Every
sql.end()on the Cloudflare build leaves two unhandled rejections.end()closed the socket right after sending Terminate, which cancelled the pending read. The read then emitted'error'afterconnection.jshad removed its listeners, and workerd also reports the cancelled read itself.Now
end()sends Terminate and closes only the write side, likesocket.end()in Node, and the socket closes when the read reaches EOF. This works with servers that close on Terminate and with ones that wait for EOF, like PGlite.error()is ignored once the socket is closed, andreadFirst()gets the same catch asread().Tested in workerd with one query per client, then
await sql.end():Fixes #1196, fixes #1202