Skip to content

fix(pg-cloudflare): batch extended query protocol writes - #3851

Open
sagarpjpt wants to merge 1 commit into
brianc:masterfrom
sagarpjpt:fix/cloudflare-cork-writes
Open

sagarpjpt wants to merge 1 commit into
brianc:masterfrom
sagarpjpt:fix/cloudflare-cork-writes

Conversation

@sagarpjpt

Copy link
Copy Markdown

Fixes #3850.

pg already calls cork() and uncork() around a parameterized query when the socket supports them. CloudflareSocket lacked those methods, so Parse, Bind, Describe, Execute, and Sync went to its underlying writer in five separate calls.

This buffers writes until the last uncork() and sends their bytes in order as one write. Buffered callbacks receive the write result in order. end() flushes before closing, and destroy() discards unsent bytes and completes their callbacks with the destruction reason.

Validation

  • The five new regression tests fail on master and pass with the fix. The protocol test checks that five writes become one with identical bytes.
  • In local workerd against PGlite over TCP, parameterized queries used one writer call each. The same connection handled another query after a rejected parameter value. The existing Workers test also passed.
  • pg unit suite, 29 ESM tests, TypeScript build, lint, and webpack, Rollup, Vite, and esbuild checks passed.

Production latency was not measured locally. Prepared with AI assistance.

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: CloudflareSocket has no cork()/uncork(), so each parameterised query costs ~50 ms over a direct connection

1 participant