@mongodb-js/oidc-plugin
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -16,2 +16,3 @@ import type { MongoDBOIDCLogEventsMap, OIDCAbortSignal, TypedEventEmitter } from './types'; | ||
private servers; | ||
private clientConnections; | ||
private readonly expressApp; | ||
@@ -18,0 +19,0 @@ private readonly redirects; |
@@ -19,2 +19,3 @@ "use strict"; | ||
this.servers = []; | ||
this.clientConnections = []; | ||
this.redirects = new Map(); | ||
@@ -347,2 +348,10 @@ this._handleSuccess = (req, res, next) => { | ||
}); | ||
server.on('connection', (socket) => { | ||
this.clientConnections.push(socket); | ||
socket.on('close', () => { | ||
const index = this.clientConnections.indexOf(socket); | ||
if (index !== -1) | ||
this.clientConnections.splice(index, 1); | ||
}); | ||
}); | ||
return server; | ||
@@ -364,8 +373,24 @@ } | ||
}); | ||
const servers = this.servers; | ||
// Node.js servers emit 'close' events in response to .close(), | ||
// but we are not waiting for that here, because: | ||
// - Those events are not actually correlated to the server closing, Node.js | ||
// just closes the underlying handle and ignores that that is an async operation | ||
// (https://github.com/nodejs/node/blob/38b82b0604d6515b281c6586d6999d2c67248e7f/lib/net.js#L2178) | ||
// - Node.js does, however, wait for all incoming connections to be closed | ||
// before emitting the event. That can be convenient sometimes, but browsers | ||
// can keep idle connections open for a while as a sort of 'connection cache', | ||
// so waiting for the 'close' event would potentially delay this event indefinitely. | ||
for (const server of this.servers) | ||
server.close(); | ||
this.servers = []; | ||
await Promise.all(servers.map(async (server) => { | ||
server.close(); | ||
await (0, events_1.once)(server, 'close'); | ||
})); | ||
for (const socket of this.clientConnections) { | ||
// Close the open sockets. Not much point in waiting for a 'close' | ||
// event here. | ||
socket.on('error', () => { | ||
/* ignore */ | ||
}); | ||
socket.destroy(); | ||
} | ||
this.clientConnections = []; | ||
return Promise.resolve(); // Keeping this async in case we ever need it to be. | ||
} | ||
@@ -372,0 +397,0 @@ /** |
@@ -16,3 +16,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/oidc-plugin", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"repository": { | ||
@@ -19,0 +19,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156164
2148