|
| 1 | +Add a heartbeat to web socket connections |
| 2 | + |
| 3 | +This prevents them from being killed when they are idle. To test run behind |
| 4 | +NGINX, make sure the sockets are idle (check dev tools), then wait 60+ seconds. |
| 5 | + |
| 6 | +Index: code-server/lib/vscode/src/vs/base/parts/ipc/common/ipc.net.ts |
| 7 | +=================================================================== |
| 8 | +--- code-server.orig/lib/vscode/src/vs/base/parts/ipc/common/ipc.net.ts |
| 9 | ++++ code-server/lib/vscode/src/vs/base/parts/ipc/common/ipc.net.ts |
| 10 | +@@ -7,6 +7,7 @@ import { VSBuffer } from 'vs/base/common |
| 11 | + import { Emitter, Event } from 'vs/base/common/event'; |
| 12 | + import { Disposable, dispose, IDisposable } from 'vs/base/common/lifecycle'; |
| 13 | + import { IIPCLogger, IMessagePassingProtocol, IPCClient } from 'vs/base/parts/ipc/common/ipc'; |
| 14 | ++import { isWeb } from 'vs/base/common/platform'; |
| 15 | + |
| 16 | + export const enum SocketDiagnosticsEventType { |
| 17 | + Created = 'created', |
| 18 | +@@ -828,6 +829,19 @@ export class PersistentProtocol implemen |
| 19 | + this._socketDisposables.push(this._socketWriter); |
| 20 | + this._socketReader = new ProtocolReader(this._socket); |
| 21 | + this._socketDisposables.push(this._socketReader); |
| 22 | ++ // Send empty messages to keep the socket alive. We only need this on the |
| 23 | ++ // web where sockets can be killed by reverse proxies for inactivity. |
| 24 | ++ if (isWeb) { |
| 25 | ++ const timer = setInterval(() => { |
| 26 | ++ const msg = new ProtocolMessage(ProtocolMessageType.None, 0, 0, getEmptyBuffer()); |
| 27 | ++ this._socketWriter.write(msg); |
| 28 | ++ }, 45000); // NGINX has a 60 second default timeout so try 45 seconds. |
| 29 | ++ this._socketDisposables.push({ |
| 30 | ++ dispose: () => { |
| 31 | ++ clearInterval(timer); |
| 32 | ++ }, |
| 33 | ++ }); |
| 34 | ++ } |
| 35 | + this._socketDisposables.push(this._socketReader.onMessage(msg => this._receiveMessage(msg))); |
| 36 | + this._socketDisposables.push(this._socket.onClose((e) => this._onSocketClose.fire(e))); |
| 37 | + if (initialChunk) { |
0 commit comments