525
*/
526
private _trackRemoteSocket(socket: Duplex): void {
528
>
529
>
// Once we detach NodeSocket's listeners (see _takeRemoteStream)
530
>
// the raw socket has no 'error' handler of its own. A net.Socket
531
>
// that emits 'error' without a listener throws as a genuine
532
>
// uncaught exception, so every socket we own must have one.
533
>
// Destroying on error tears the socket down quietly and lets the
534
>
// agent evict it from the pool. (CONNECT bridges attach an
535
>
// additional handler in _bridgeSockets; a second listener is
536
>
// harmless.)
537
>
socket.on('error', () => socket.destroy());
538
>
socket.on('close', () => this._remoteSockets.delete(socket));
539
>
}
540
}
541