Skip to content

fix(pg-cloudflare): emit the destroy error so a connect timeout says why - #3810

Open
pedroapfilho wants to merge 1 commit into
brianc:masterfrom
pedroapfilho:fix/pg-cloudflare-destroy-reason
Open

pedroapfilho wants to merge 1 commit into
brianc:masterfrom
pedroapfilho:fix/pg-cloudflare-destroy-reason

Conversation

@pedroapfilho

Copy link
Copy Markdown

Fixes #3809.

Client#connect times out with con.stream.destroy(new Error('timeout expired')), and CloudflareSocket#destroy dropped that error and only called end(). The client then saw a bare 'close' and rejected with Connection terminated unexpectedly.

destroy(error) now does what net.Socket#destroy(error) does: it emits 'error' with the reason, then 'close'. The error is queued before end() runs, so it still arrives first when the socket's close() resolves right away. destroy() without an argument, which is every other call in pg and pg-pool, behaves as before.

Tests, in pg-esm-test/pg-cloudflare.test.js:

  • destroy(error) emits that error, and before 'close' (fails without this change)
  • destroy() emits no error

Checked in workerd too (wrangler dev, nodejs_compat, connectionTimeoutMillis: 500, a TCP listener that never answers):

before: Connection terminated unexpectedly after 502 ms
after:  timeout expired after 502 ms

This touches destroy() only, so it shouldn't conflict with #3784, #3806 or #3718.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pg-cloudflare: a connect timeout is reported as "Connection terminated unexpectedly"

1 participant