Skip to content

fix(ext/node): fix TLS JSStreamSocket resource leak causing process hang#32325

Merged
fraidev merged 9 commits intodenoland:mainfrom
fraidev:fix/tls-jsstreamsocket-resource-leak
Mar 11, 2026
Merged

fix(ext/node): fix TLS JSStreamSocket resource leak causing process hang#32325
fraidev merged 9 commits intodenoland:mainfrom
fraidev:fix/tls-jsstreamsocket-resource-leak

Conversation

@fraidev
Copy link
Copy Markdown
Contributor

@fraidev fraidev commented Feb 25, 2026

Closes #30556

When tls.connect({ socket }) receives a non-net.Socket stream (e.g. mssql/tedious wrapping TDS framing in a Duplex via native-duplexpair), Deno creates a JSStreamSocket to bridge the JS stream to Rust TLS resources. A circular Rc dependency between JSDuplexResource and JSStreamTlsResource prevented either from being dropped after close, keeping a pending core.read() alive and the event loop running indefinitely.

Fixes at three layers:

  • (tls.rs): Add Resource::close() to JSDuplexResource using AtomicBool + tokio::sync::Notify to break pending reads without mutex deadlock, releasing the circular Rc dependency.

  • (_tls_wrap.js): Add JSStreamSocket.close() so the _onClose() -> kStreamBaseField.close() path properly closes both TLS and channel resources.

  • (stream_wrap.ts): Treat Deno.errors.UnexpectedEof as EOF alongside Interrupted and BadResource, fixing a pre-existing unhandled error on TLS peer close.

@fraidev fraidev marked this pull request as draft February 25, 2026 16:23
@fraidev fraidev added the ci-draft Run the CI on draft PRs. label Feb 25, 2026
@fraidev fraidev force-pushed the fix/tls-jsstreamsocket-resource-leak branch 2 times, most recently from 5ae8e87 to 22c2bf8 Compare March 2, 2026 11:34
@fraidev fraidev force-pushed the fix/tls-jsstreamsocket-resource-leak branch from 22c2bf8 to 90bf3e7 Compare March 9, 2026 23:45
@fraidev fraidev force-pushed the fix/tls-jsstreamsocket-resource-leak branch from 90bf3e7 to 7d972d9 Compare March 10, 2026 00:19
@fraidev fraidev marked this pull request as ready for review March 10, 2026 00:21
@fraidev fraidev removed the ci-draft Run the CI on draft PRs. label Mar 10, 2026
@fraidev fraidev requested a review from littledivy March 10, 2026 12:45
Copy link
Copy Markdown
Contributor

@kajukitli kajukitli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes. No issues found.

Copy link
Copy Markdown
Contributor

@kajukitli kajukitli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes. No issues found.

Copy link
Copy Markdown
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fraidev fraidev merged commit 26972e6 into denoland:main Mar 11, 2026
155 of 180 checks passed
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.

mssql close() is not working

3 participants