Skip to content

Commit

Permalink
Fix temp client websocket leaking
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <zyl.skysniper@gmail.com>
  • Loading branch information
yilunzhang committed Jul 1, 2020
1 parent 0ef73c8 commit 15cf40d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,21 @@ client.onConnect(() => {
}
}, pingInterval);
let lastForceUpdateTime = new Date();
let tempClient;
setInterval(async () => {
if (tempClient) {
tempClient.close().catch(e => {
console.error('Close temp client error:', e);
});
}

let tempIdentifier = _nknSdk.default.util.randomBytesHex(4);

if (identifier) {
tempIdentifier += '.' + identifier;
}

let tempClient = new _nknSdk.default.MultiClient({
tempClient = new _nknSdk.default.MultiClient({
originalClient: true,
seed: wallet.getSeed(),
identifier: tempIdentifier
Expand All @@ -356,6 +363,11 @@ client.onConnect(() => {
}
}
}

tempClient.close().catch(e => {
console.error('Close temp client error:', e);
});
tempClient = null;
}, 3000);
});
}, forcePingInterval);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nkn-shell-daemon",
"version": "1.0.7",
"version": "1.0.9",
"description": "NKN Shell Daemon",
"main": "nshd.js",
"bin": {
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,18 @@ client.onConnect(() => {
}, pingInterval)

let lastForceUpdateTime = new Date()
let tempClient
setInterval(async () => {
if (tempClient) {
tempClient.close().catch((e) => {
console.error('Close temp client error:', e);
})
}
let tempIdentifier = nkn.util.randomBytesHex(4)
if (identifier) {
tempIdentifier += '.' + identifier
}
let tempClient = new nkn.MultiClient({
tempClient = new nkn.MultiClient({
originalClient: true,
seed: wallet.getSeed(),
identifier: tempIdentifier,
Expand All @@ -331,6 +337,10 @@ client.onConnect(() => {
}
}
}
tempClient.close().catch((e) => {
console.error('Close temp client error:', e);
})
tempClient = null
}, 3000);
})
}, forcePingInterval)
Expand Down

0 comments on commit 15cf40d

Please sign in to comment.