File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -747,12 +747,11 @@ class Server {
747
747
} ) ;
748
748
}
749
749
750
- close ( cb ) {
751
- this . sockets . forEach ( ( socket ) => {
752
- this . socketServer . closeConnection ( socket ) ;
753
- } ) ;
754
-
755
- this . sockets = [ ] ;
750
+ close ( callback ) {
751
+ if ( this . socketServer ) {
752
+ this . socketServer . close ( ) ;
753
+ this . sockets = [ ] ;
754
+ }
756
755
757
756
const prom = Promise . all (
758
757
this . staticWatchers . map ( ( watcher ) => watcher . close ( ) )
@@ -762,7 +761,7 @@ class Server {
762
761
this . server . kill ( ( ) => {
763
762
// watchers must be closed before closing middleware
764
763
prom . then ( ( ) => {
765
- this . middleware . close ( cb ) ;
764
+ this . middleware . close ( callback ) ;
766
765
} ) ;
767
766
} ) ;
768
767
}
Original file line number Diff line number Diff line change @@ -72,6 +72,16 @@ module.exports = class SockJSServer extends BaseServer {
72
72
connection . write ( message ) ;
73
73
}
74
74
75
+ close ( callback ) {
76
+ [ ...this . server . sockets ] . forEach ( ( socket ) => {
77
+ this . closeConnection ( socket ) ;
78
+ } ) ;
79
+
80
+ if ( callback ) {
81
+ callback ( ) ;
82
+ }
83
+ }
84
+
75
85
closeConnection ( connection ) {
76
86
connection . close ( ) ;
77
87
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ module.exports = class WebsocketServer extends BaseServer {
31
31
32
32
const noop = ( ) => { } ;
33
33
34
- setInterval ( ( ) => {
34
+ const interval = setInterval ( ( ) => {
35
35
this . implementation . clients . forEach ( ( socket ) => {
36
36
if ( socket . isAlive === false ) {
37
37
return socket . terminate ( ) ;
@@ -41,6 +41,10 @@ module.exports = class WebsocketServer extends BaseServer {
41
41
socket . ping ( noop ) ;
42
42
} ) ;
43
43
} , this . server . webSocketHeartbeatInterval ) ;
44
+
45
+ this . implementation . on ( 'close' , ( ) => {
46
+ clearInterval ( interval ) ;
47
+ } ) ;
44
48
}
45
49
46
50
send ( connection , message ) {
@@ -52,6 +56,10 @@ module.exports = class WebsocketServer extends BaseServer {
52
56
connection . send ( message ) ;
53
57
}
54
58
59
+ close ( callback ) {
60
+ this . implementation . close ( callback ) ;
61
+ }
62
+
55
63
closeConnection ( connection ) {
56
64
connection . close ( ) ;
57
65
}
You can’t perform that action at this time.
0 commit comments