Skip to content

Commit

Permalink
Fix remoteAddress workaround
Browse files Browse the repository at this point in the history
Tree shaking removed the remoteAddress workaround because property access
should have no side effect. This change prevents that.
  • Loading branch information
zaidka committed Sep 24, 2019
1 parent 559aa0f commit 209c0f7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/cwmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 209c0f7

Please sign in to comment.