Repository navigation
fix(net): keep guest TLS aborts from crashing Bun hosts - #154
Open
guillemborrell wants to merge 1 commit into
Open
guillemborrell wants to merge 1 commit into
guillemborrell wants to merge 1 commit into
Conversation
When a guest closes an intercepted TLS flow while the host still has ciphertext pending (e.g. after rejecting the MITM certificate), the pending guest write fails with "guest closed" and the wrapped GuestTlsStream emits 'error'. Node forwards it to the TLS socket; Bun does not, so it became an uncaught exception that terminated the host process and every VM in it. Listen for the stream error and destroy only that flow's TLS socket. Adds a VM-free regression test that reproduces the crash on Bun.
guillemborrell
marked this pull request as ready for review
October 5, 2026 17:46
This branch has not been deployed
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.
Follow-up to #152.
When a guest closes an intercepted TLS flow while the host still has ciphertext pending, the host process crashes on Bun. Rejecting the MITM certificate is enough to trigger it: custom CA bundles,
certifi, pinning, or any HTTPS in a VM without the MITM CA mounted (vfs: null).The pending guest write in
GuestTlsStreamfails with "guest closed", and the wrapped stream emitserror. That stream has noerrorlistener:TLSSocket, so nothing breaks.The
endNT → shutdown → _write → waitForFlowResumestack shows the trigger is the final write fromtlsSocket.end()afterhandleTcpClose.Fix
Add an
errorlistener on the guest stream that destroys only that flow's TLS socket, and emit a debug message for errors other than guest-closed. This is a no-op on Node.Test
tls-mitm-sni.test.tsgains a VM-free case:handleTcpClose({ destroy: false })while the host's writes are flow-control paused.GuestClosedErroruncaught)On a real VM (macOS arm64, krun): an HTTPS attempt in a deny-all VM, and a guest
curl --cacert <unrelated CA>in an allowlist VM, each crashed a Bun host before this change. After it, the host survives and keeps serving, on both runtimes.node --test test/*.test.ts: 643 pass, 13 skipped, 4 fail. The four failures (clock-sync, vfs-many-mounts, vfs chmod, exec deleteFile) also fail onmainon this machine.