Repository navigation
Conversation
pg's Connection calls stream.write(buffer) without a callback. When the Cloudflare writer rejected, the error went to a default no-op callback and was lost; the application only saw a later "Connection terminated unexpectedly". Now, when no callback is given, the rejection is emitted as an 'error' event, as a Node net.Socket would do. A caller that passes a callback still gets the error there, as before. Part of brianc#3757 (the error-reporting half; chunking large writes is not changed here).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #3757 (the error-reporting half only).
Connection._send()callsstream.write(buffer)with no callback. InCloudflareSocket.write()the callback defaulted to a no-op, so when the Cloudflare writer rejected, the rejection was dropped. The app then only saw a later "Connection terminated unexpectedly", with no hint of why. charmander asked on the issue whether a usefulwrite()rejection was being swallowed, and it is.With this change, if no callback was passed, the rejection is emitted as
'error', the same way anet.Socketreports a failed write.Connectionalready listens for'error'on the stream and passes it on to the client. Callers that pass a callback (such asend()) still get the error in the callback, and nothing else changes.Two tests added to
pg-esm-test/pg-cloudflare.test.js, in the style of the existing ones (fake_cfWriter):'error'with the original error'error'is emittedThis is the same approach as #3784, which its author closed on Oct 23 without a review.
This does not change how large writes are sent (the chunking/backpressure part of the issue). I couldn't verify that part without deploying a Worker.