Fix remoteAddress workaround

Tree shaking removed the remoteAddress workaround because property access
should have no side effect. This change prevents that.
This commit is contained in:
Zaid Abdulla committed 2019-09-23 22:12:32 -07:00
1 parent 559aa0fd36
commit 209c0f7620
1 file changed
+6 -2
+6 -2
View File
@@ -824,11 +824,15 @@ async function getSession(connection, sessionId): Promise<SessionContext> {
return session.deserialize(sessionContextString);
}
// Only needed to prevent tree shaking from removing the remoteAddress
// workaround in onConnection function.
const remoteAddressWorkaround = new WeakMap<Socket, string>();
// When socket closes, store active sessions in cache
export function onConnection(socket): void {
export function onConnection(socket: Socket): void {
// The property remoteAddress may be undefined after the connection is
// closed, unless we read it at least once (caching?)
socket.remoteAddress;
remoteAddressWorkaround.set(socket, socket.remoteAddress);
socket.on("close", async () => {
const sessionContext = currentSessions.get(socket);