From 209c0f76203b830cf1c2422bfadd361c3205e33d Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Mon, 23 Sep 2019 22:12:32 -0700 Subject: [PATCH] Fix remoteAddress workaround Tree shaking removed the remoteAddress workaround because property access should have no side effect. This change prevents that. --- lib/cwmp.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cwmp.ts b/lib/cwmp.ts index 3daf1ab..fdafc11 100644 --- a/lib/cwmp.ts +++ b/lib/cwmp.ts @@ -824,11 +824,15 @@ async function getSession(connection, sessionId): Promise { return session.deserialize(sessionContextString); } +// Only needed to prevent tree shaking from removing the remoteAddress +// workaround in onConnection function. +const remoteAddressWorkaround = new WeakMap(); + // 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);