Title: tls.connect() ignores the `session` option when `socket` is provided (regression v22.22.3 → v22.23.1) · Issue #64402 · nodejs/node · GitHub
Open Graph Title: tls.connect() ignores the `session` option when `socket` is provided (regression v22.22.3 → v22.23.1) · Issue #64402 · nodejs/node
X Title: tls.connect() ignores the `session` option when `socket` is provided (regression v22.22.3 → v22.23.1) · Issue #64402 · nodejs/node
Description: Version v22.23.1 Platform Linux (docker node:22.23.1-bookworm-slim, x86_64); also reproduced on the non-slim image Subsystem tls What steps will reproduce the bug? Run the self-contained script below (starts a local TLS 1.2 server, then ...
Open Graph Description: Version v22.23.1 Platform Linux (docker node:22.23.1-bookworm-slim, x86_64); also reproduced on the non-slim image Subsystem tls What steps will reproduce the bug? Run the self-contained script bel...
X Description: Version v22.23.1 Platform Linux (docker node:22.23.1-bookworm-slim, x86_64); also reproduced on the non-slim image Subsystem tls What steps will reproduce the bug? Run the self-contained script bel...
Opengraph URL: https://github.com/nodejs/node/issues/64402
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tls.connect() ignores the `session` option when `socket` is provided (regression v22.22.3 → v22.23.1)","articleBody":"### Version\n\nv22.23.1\n\n### Platform\n\n```text\nLinux (docker node:22.23.1-bookworm-slim, x86_64); also reproduced on the non-slim image\n```\n\n### Subsystem\n\ntls\n\n### What steps will reproduce the bug?\n\nRun the self-contained script below (starts a local TLS 1.2 server, then connects twice offering the first connection's session):\n\n```js\n// Repro: tls.connect() ignores the `session` option when `socket` is provided.\n// Resuming a TLS 1.2 session works with a direct tls.connect({host, port,\n// session}) but silently does a full handshake when upgrading an existing\n// net.Socket via tls.connect({socket, session}). Regressed between v22.22.3\n// (wrapped path resumes) and v22.23.1 (wrapped path ignores the session).\n//\n// Real-world impact: FTPS servers with vsftpd require_ssl_reuse (e.g. Bambu\n// Lab H2D 3D printers) reject every data connection from clients like\n// basic-ftp, which upgrade the already-connected data socket and pass\n// `session` exactly this way.\n'use strict'\nconst tls = require('node:tls')\nconst net = require('node:net')\n\n// Throwaway self-signed localhost cert so the repro is a single file.\nconst key = `-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDsN1UvQ0kux/m8\nsnGI8rPBL5kXYXe2E1IV/V8ImQDbFouay2bZIL4vPdhVsNGH7+oprUtQ9sgpKNue\nGN96aGcIsUSZN6HcvFZhS78dk6FTBDaSVbUFijp59WS1WdLmmkFYva7SLGJ5VE9A\n2tB4DSPcw0ofqESV2YMhHfsc4RhXJ6FcumWPv8yosT3lJAdZjxoBuxGtysY89bff\n6ZNBIFnS8tb1W+L2qAk3p7GEIklJUDemmt1HDwu4vA/820Y0UB+KFNLNT4S/wUKw\nJ7nWJfLQ1A9BiQiRsJgHqRykXYFB9BO0uuQw+SxXtMEqU5CtlnB8Jf2LOfLbhjBx\nacwD7oqfAgMBAAECggEAE+l8LE5DOobP9giiynUPEw9km9RzB22sgz8HBk4DhPRr\nE0LnKhF5BrlzZZHQr+FY/2dkzG/pIpMXpEWbfRGU8eYjjrjiU52quGvusdsSg9F8\nmixQZKWo1UQK18C5JwhEzuq6dGwaZvjk72YioaQV7FOoCXAhS/J4e8+vrdkJuLrs\niT5VvaB+Lpw6Se3OszyWQ4ceFs9WZPLljlxTFFXAADVvgIdMryygotag7zHvbXes\nq7Gw/XaIm/RME1I3b7wxYQLeHn1lVQwb5ZjaSZB/2UEa6/s9PCNuerxJMg52cXKA\nBDX6txAOyNoQBXU2aHmw7hGWfE2zYvSR9LO4j0RyMQKBgQD2wSwqd/CvYjEAS49e\nhjPYr0jbrXVPHxUZeJvliQq3J4ocH+ARDUankVVbJmgxa4WccmDbLGFQil2UXHad\nPMTAwysL1Fgvq9NabPJjqsBHLw0UPupDysI99c0K9EvfgjsUVBvtHhx1OSPJRtoa\nhLhQpoAO0ASMn7iE7NezuzcW0QKBgQD1ERPNx+7RsQ/NuvC6qgI85DAaVxtqi6oN\n6A/ddsz7wh5A0y0Io6Yca7ax8LJ86c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rQeA0j3MNKH6hEldmDIR37HOEYVyeh\nXLplj7/MqLE95SQHWY8aAbsRrcrGPPW33+mTQSBZ0vLW9Vvi9qgJN6exhCJJSVA3\npprdRw8LuLwP/NtGNFAfihTSzU+Ev8FCsCe51iXy0NQPQYkIkbCYB6kcpF2BQfQT\ntLrkMPksV7TBKlOQrZZwfCX9izny24YwcWnMA+6KnwIDAQABo1MwUTAdBgNVHQ4E\nFgQUCn1orlDMdSN/3DcjQ0vIJGEamMswHwYDVR0jBBgwFoAUCn1orlDMdSN/3Dcj\nQ0vIJGEamMswDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAp+a/\ncjmmEP0kbSNX8DMQfhhOV+sJhIQaeRP/uFlUmOwJq/BjoZyWUqfU94j6/VLM3ssz\n6vYduhgTmQsy3oC/a73YHB5SwmwiT2CbQQ99zyoj65ZXIAFgsrPEEe3g4ufSuP5t\nIFtKM6+QspM4VBWlXiUpI/AzPr7L2d9sJGoKTDSgnL+0YQx4PDeAixXtABKa6C+r\n+olQEjaqnucctM3Rvr25co2scxbm7broFGLiFF26JyRKZjoatROB26Yp19QGdQHl\nL5+7VMHzOa4fc5plpfZ+pEcGDdWA0jGhBTnwami9N9FpMW2/D/2PYh2TGj7nJ5vx\nKfOP+J+ltK+bfdET5Q==\n-----END CERTIFICATE-----`\n\nconst server = tls.createServer({ key, cert, maxVersion: 'TLSv1.2' })\nserver.listen(0, '127.0.0.1', async () => {\n const port = server.address().port\n const connectFresh = (session) => new Promise((resolve, reject) => {\n const s = tls.connect({ host: '127.0.0.1', port, rejectUnauthorized: false, maxVersion: 'TLSv1.2', session }, () => resolve(s))\n s.once('error', reject)\n })\n const connectWrapped = (session) => new Promise((resolve, reject) => {\n const plain = net.connect({ host: '127.0.0.1', port }, () => {\n const s = tls.connect({ socket: plain, rejectUnauthorized: false, maxVersion: 'TLSv1.2', session }, () => resolve(s))\n s.once('error', reject)\n })\n plain.once('error', reject)\n })\n\n const first = await connectFresh()\n const session = first.getSession()\n first.destroy()\n\n const fresh = await connectFresh(session)\n console.log(`fresh tls.connect({host, port, session}): isSessionReused = ${fresh.isSessionReused()}`)\n fresh.destroy()\n\n const wrapped = await connectWrapped(session)\n console.log(`wrapped tls.connect({socket, session}): isSessionReused = ${wrapped.isSessionReused()}`)\n const ok = wrapped.isSessionReused()\n wrapped.destroy()\n\n console.log(ok ? 'OK' : 'BUG: session option ignored on the wrapped-socket path')\n server.close()\n process.exitCode = ok ? 0 : 1\n})\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways on v22.23.1. The required condition is passing an already-connected `net.Socket` via the `socket` option together with `session`.\n\n### What is the expected behavior? Why is that the expected behavior?\n\nBoth connections should resume the offered session (`isSessionReused() === true`), as documented for the `session` option and as v22.22.3 behaves:\n\n```text\nfresh tls.connect({host, port, session}): isSessionReused = true\nwrapped tls.connect({socket, session}): isSessionReused = true\nOK\n```\n\n### What do you see instead?\n\nOn v22.23.1 the wrapped-socket path silently performs a full handshake — the `session` option is accepted but has no effect:\n\n```text\nfresh tls.connect({host, port, session}): isSessionReused = true\nwrapped tls.connect({socket, session}): isSessionReused = false\nBUG: session option ignored on the wrapped-socket path\n```\n\nBisected across release lines: v22.22.3 resumes on both paths; v22.23.1 only on the fresh path.\n\n### Additional information\n\nReal-world impact: FTPS servers running vsftpd with `require_ssl_reuse` (notably Bambu Lab H2-series 3D printers) require every data connection to resume the control connection's TLS session, and reject the transfer otherwise (`522 SSL connection failed: session reuse required`). FTP clients such as `basic-ftp` implement this by upgrading the already-connected passive data socket with `tls.connect({ socket, session: controlSocket.getSession() })` — exactly the path this regression breaks — so on v22.23.x every such transfer fails while the same code works on earlier releases. (Working around it in our application by using a fresh `tls.connect` for the data connection.)\n","author":{"url":"https://github.com/RyanEwen","@type":"Person","name":"RyanEwen"},"datePublished":"2026-07-10T05:16:09Z","url":"https://github.com/nodejs/node/issues/64402"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d611adbe-b9ad-7bc7-9395-c6e27ca3d171 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EE1A:2AEFEF:4CEB79:674BFF:6AFBEFF0 |
| html-safe-nonce | 2bcc2d56955668bade8aebf2080fb9ec8a789ca04adc32a637d112fd23e5c293 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTFBOjJBRUZFRjo0Q0VCNzk6Njc0QkZGOjZBRkJFRkYwIiwidmlzaXRvcl9pZCI6IjM5MDE0NjA4OTA4OTY4MjIyNTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 155373339e5b81bea4d1ff60f5bc3675d0d92ec0148d228033b6e5ccfb7249cb |
| hovercard-subject-tag | issue:4852235988 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/64402/issue_layout |
| twitter:image | https://opengraph.githubassets.com/539ee76d235fbc5a752ea6e63df4b7f10e5d3636b94ff8a3cce89c5f11d38abe/nodejs/node/issues/64402 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/539ee76d235fbc5a752ea6e63df4b7f10e5d3636b94ff8a3cce89c5f11d38abe/nodejs/node/issues/64402 |
| og:image:alt | Version v22.23.1 Platform Linux (docker node:22.23.1-bookworm-slim, x86_64); also reproduced on the non-slim image Subsystem tls What steps will reproduce the bug? Run the self-contained script bel... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RyanEwen |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width