This repository was archived by the owner on Aug 29, 2023. It is now read-only.
File tree 1 file changed +22
-2
lines changed
1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,17 @@ function TCP () {
56
56
}
57
57
handler ( conn )
58
58
} )
59
+
60
+ listener . __connections = { }
61
+ listener . on ( 'connection' , ( conn ) => {
62
+ const key = `${ conn . remoteAddress } :${ conn . remotePort } `
63
+ listener . __connections [ key ] = conn
64
+
65
+ conn . on ( 'close' , ( ) => {
66
+ delete listener . __connections [ key ]
67
+ } )
68
+ } )
69
+
59
70
listener . listen ( m . toOptions ( ) , ( ) => {
60
71
// Node.js likes to convert addr to IPv6 (when 0.0.0.0 for e.g)
61
72
const address = listener . address ( )
@@ -86,13 +97,22 @@ function TCP () {
86
97
}
87
98
88
99
this . close = ( callback ) => {
100
+ const closeTimeout = 300
101
+
89
102
if ( listeners . length === 0 ) {
90
103
log ( 'Called close with no active listeners' )
91
104
return callback ( )
92
105
}
93
106
94
- parallel ( listeners . map ( ( listener ) => {
95
- return ( cb ) => listener . close ( cb )
107
+ parallel ( listeners . map ( ( listener ) => ( cb ) => {
108
+ setTimeout ( ( ) => {
109
+ Object . keys ( listener . __connections ) . forEach ( ( key ) => {
110
+ log ( 'destroying %s' , key )
111
+ listener . __connections [ key ] . destroy ( )
112
+ } )
113
+ } , closeTimeout )
114
+
115
+ listener . close ( cb )
96
116
} ) , callback )
97
117
}
98
118
You can’t perform that action at this time.
0 commit comments