Skip to content

Commit 43b87ed

Browse files
authored
fix: socket disconnections behind reverse proxies (#5451)
1 parent b091b00 commit 43b87ed

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

patches/heartbeat.diff

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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) {

patches/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ disable-downloads.diff
2020
telemetry.diff
2121
display-language.diff
2222
cli-window-open.diff
23+
heartbeat.diff

0 commit comments

Comments
 (0)