@@ -42,25 +42,36 @@ async function run (localHost, controlPort, proxyConfig) {
4242 } ,
4343 // Disable connecting
4444 [ '/pause' ] ( ) {
45- let connectionsClosed
45+ let connectionsJustClosed = 0
46+ let connectionsAlreadyClosed = 0
4647 if ( canConnect ) {
4748 console . log ( '🟠 Disabling new connections' )
4849 canConnect = false
49- connectionsClosed = connections . size
50- if ( connectionsClosed > 0 ) {
51- console . log ( 'Closing' , connectionsClosed , 'open connection(s)' )
50+ if ( connectionsJustClosed > 0 ) {
51+ console . log ( 'Closing' , connectionsJustClosed , 'open connection(s)' )
5252 for ( const connection of connections ) {
5353 try {
5454 connection . close ( )
55- console . log ( 'Closed connection' , connection )
55+ console . log ( 'Closed:' , connection . localAddr , '<->' , connection . remoteAddr )
56+ connectionsJustClosed ++
5657 } catch ( e ) {
57- console . error ( 'Failed to close connection' , connection , 'because of' , e )
58+ if ( e . name === 'BadResource' ) {
59+ console . log ( 'Already closed:' , connection . localAddr , '<->' , connection . remoteAddr )
60+ connectionsAlreadyClosed ++
61+ } else {
62+ throw e
63+ }
5864 }
5965 connections . delete ( connection )
6066 }
6167 }
6268 }
63- return respond ( 200 , { canConnect, connections : connections . size , connectionsClosed } )
69+ return respond ( 200 , {
70+ canConnect,
71+ connections : connections . size ,
72+ connectionsJustClosed,
73+ connectionsAlreadyClosed
74+ } )
6475 } ,
6576 } , {
6677 onMessage : async ( { event } ) => {
0 commit comments