Skip to content

Commit

Permalink
chore: more aggressive unpiping
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Jun 30, 2022
1 parent f06b8ea commit 8e95000
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/fixtures/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ class Proxy extends EventEmitter {

const proxy = net.connect(connectOptions, () => {
socket.write(OK_MSG, () => {
// if the proxy socket emits end, it's because the server has disconnected us, so we
// need to disconnect our pipe since it's possible our internal socket will still be
// trying to write which will fail
proxy.once('end', () => {
// if either socket emits end, we need to disconnect our pipes or we could accidentally
// try to write to a socket that's no longer accepting writes
const onEnd = () => {
proxy.unpipe(socket)
socket.unpipe(proxy)
})
}
proxy.once('end', onEnd)
socket.once('end', onEnd)
socket.pipe(proxy)
proxy.pipe(socket)
})
Expand Down

0 comments on commit 8e95000

Please sign in to comment.