| 189 | |
| 190 | const secondaryServer = getServerInstance(serverOpts, httpHandler) |
| 191 | const closeSecondary = () => { |
| 192 | // To avoid falling into situations where the close of the |
| 193 | // secondary server is triggered before the preClose hook |
| 194 | // is done running, we better wait until the main server is closed. |
| 195 | // No new TCP connections are accepted |
| 196 | // We swallow any error from the secondary server |
| 197 | secondaryServer.close(() => {}) |
| 198 | if (typeof secondaryServer.closeAllConnections === 'function' && serverOpts.forceCloseConnections === true) { |
| 199 | secondaryServer.closeAllConnections() |
| 200 | } |
| 201 | if (typeof secondaryServer.closeHttp2Sessions === 'function') { |
| 202 | secondaryServer.closeHttp2Sessions() |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | secondaryServer.on('upgrade', mainServer.emit.bind(mainServer, 'upgrade')) |
| 207 | mainServer.on('unref', closeSecondary) |