Skip to content

Commit

Permalink
set keepalive header on watch requests
Browse files Browse the repository at this point in the history
This fix sends keep-alive probes to the server every 30 seconds.

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
  • Loading branch information
Matthew Fisher committed Apr 7, 2021
1 parent 5dd9180 commit bd762eb
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
88 changes: 83 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"isomorphic-ws": "^4.0.1",
"js-yaml": "^3.13.1",
"jsonpath-plus": "^0.19.0",
"net-keepalive": "2.0.4",
"openid-client": "^4.1.1",
"request": "^2.88.0",
"rfc4648": "^1.3.0",
Expand Down
5 changes: 5 additions & 0 deletions src/watch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import byline = require('byline');
import request = require('request');
import keepalive = require('net-keepalive');
import { Duplex } from 'stream';
import { KubeConfig } from './config';

Expand Down Expand Up @@ -112,6 +113,10 @@ export class Watch {
req = this.requestImpl.webRequest(requestOptions);
const stream = byline.createStream();
req.on('error', doneCallOnce);
req.on('socket', function(socket) {
socket.setKeepAlive(true);
keepalive.setKeepAliveInterval(socket, 30000);
});
stream.on('error', doneCallOnce);
stream.on('close', () => doneCallOnce(null));
stream.on('data', (line) => {
Expand Down

0 comments on commit bd762eb

Please sign in to comment.