Skip to content

Commit

Permalink
Clearing secureSocket collection
Browse files Browse the repository at this point in the history
  • Loading branch information
pbharat84 committed Apr 18, 2020
1 parent 433a587 commit e1ca112
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/factories/createInternalHttpTerminator.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export default (configurationInput: HttpTerminatorConfigurationInputType): Inter
const destroySocket = (socket) => {
socket.destroy();

sockets.delete(socket);
if (socket.server instanceof http.Server) {
sockets.delete(socket);
} else {
secureSockets.delete(socket);
}
};

const terminate = async () => {
Expand Down Expand Up @@ -128,6 +132,14 @@ export default (configurationInput: HttpTerminatorConfigurationInputType): Inter
}
}

if (secureSockets.size) {
await delay(configuration.gracefulTerminationTimeout);

for (const socket of secureSockets) {
destroySocket(socket);
}
}

server.close((error) => {
if (error) {
rejectTerminating(error);
Expand Down
23 changes: 23 additions & 0 deletions test/http-terminator/factories/createInternalHttpTerminator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import got from 'got';
import KeepAliveHttpAgent from 'agentkeepalive';
import createHttpServer from '../../helpers/createHttpServer';
import createInternalHttpTerminator from '../../../src/factories/createInternalHttpTerminator';
import createHttpsServer from '../../helpers/createHttpsServer';

test('terminates HTTP server with no connections', async (t) => {
// eslint-disable-next-line ava/use-t-well
Expand Down Expand Up @@ -220,3 +221,25 @@ test('empties internal socket collection', async (t) => {

await terminator.terminate();
});

test('empties internal socket collection for https server', async (t) => {
// eslint-disable-next-line ava/use-t-well
t.timeout(500);

const httpsServer = await createHttpsServer((incomingMessage, outgoingMessage) => {
outgoingMessage.end('foo');
});

const terminator = createInternalHttpTerminator({
gracefulTerminationTimeout: 150,
server: httpsServer.server,
});

await got(httpsServer.url);

await delay(50);

t.is(terminator.secureSockets.size, 0);

await terminator.terminate();
});

0 comments on commit e1ca112

Please sign in to comment.