Skip to content

Cloudflare Workers: open the socket secure from the first byte for sslnegotiation: 'direct' - #1272

Open
dinodeSimon wants to merge 1 commit into
porsager:masterfrom
dinodeSimon:workers-direct-tls
Open

dinodeSimon wants to merge 1 commit into
porsager:masterfrom
dinodeSimon:workers-direct-tls

Conversation

@dinodeSimon

Copy link
Copy Markdown

sslnegotiation: 'direct' (Postgres 17: TLS from the first byte, no SSLRequest round trip) is accepted by the options and skips the SSLRequest in src/connection.js, but on Cloudflare Workers the connection then never finishes: cf/polyfills.js opens the socket with secureTransport: 'starttls' and its tls.connect upgrades it with startTls(), which a direct connection never asks for the server to agree to, so the connect times out (CONNECT_TIMEOUT).

This opens the socket with secureTransport: 'on' when the connection is direct, and has the shim's tls.connect only say it is connected (there is nothing to upgrade). socket.direct is set in src/connection.js beside socket.ssl; the cf, cjs and deno copies are regenerated with the transpile scripts. Nothing changes for the other sslnegotiation values.

Tested from a Worker against Neon's pooler (Sydney): a client a call, nine reads each, interleaved six times, 60 calls each: p50 26-27 ms with direct against 26-30 ms without (about 2 ms, the SSLRequest round trip), no errors. Neon's pooler accepted the handshake without ALPN (Workers' connect() takes no ALPN option).

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.

1 participant