Skip to content

Commit

Permalink
Use TCP keepalive probes to detect local log stream closing
Browse files Browse the repository at this point in the history
Change-type: patch
Closes: #1219
Signed-off-by: Cameron Diver <[email protected]>
  • Loading branch information
Cameron Diver committed May 13, 2019
1 parent ff8d784 commit 440501c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/utils/device/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as Bluebird from 'bluebird';
import * as _ from 'lodash';
import * as request from 'request';
import * as Stream from 'stream';
import * as NetKeepalive from 'net-keepalive';

import Logger = require('../logger');
import * as ApiErrors from './errors';
Expand Down Expand Up @@ -183,6 +184,12 @@ export class DeviceAPI {
),
);
}
res.socket.setKeepAlive(true, 1000);
// We send a tcp keepalive probe once every 5 seconds
NetKeepalive.setKeepAliveInterval(res.socket, 5000);
// After 5 failed probes, the connection is marked as
// closed
NetKeepalive.setKeepAliveProbes(res.socket, 5);
resolve(res);
});
});
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/device/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export function displayDeviceLogs(
});

logs.on('error', reject);
logs.on('end', resolve);
logs.on('end', () => {
logger.logError('Connection to device lost');
resolve();
});
});
}

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@types/lodash": "4.14.112",
"@types/mixpanel": "2.14.0",
"@types/mkdirp": "0.5.2",
"@types/net-keepalive": "^0.4.0",
"@types/node": "6.14.2",
"@types/prettyjson": "0.0.28",
"@types/raven": "2.5.1",
Expand Down Expand Up @@ -153,6 +154,7 @@
"moment": "^2.24.0",
"moment-duration-format": "^2.2.1",
"mz": "^2.6.0",
"net-keepalive": "^1.2.1",
"node-cleanup": "^2.1.2",
"opn": "^5.5.0",
"prettyjson": "^1.1.3",
Expand Down

0 comments on commit 440501c

Please sign in to comment.