Skip to content

Commit 6747376

Browse files
authored
Send a message every 5 seconds to avoid the underlying connection becoming idle (microsoft#159239)
Fixes microsoft#153892: Send a message every 5 seconds to avoid the unerlying connection becoming idle
1 parent c9a97b5 commit 6747376

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/vs/base/parts/ipc/common/ipc.net.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ const enum ProtocolMessageType {
262262
Disconnect = 5,
263263
ReplayRequest = 6,
264264
Pause = 7,
265-
Resume = 8
265+
Resume = 8,
266+
KeepAlive = 9,
266267
}
267268

268269
function protocolMessageTypeToString(messageType: ProtocolMessageType) {
@@ -275,6 +276,7 @@ function protocolMessageTypeToString(messageType: ProtocolMessageType) {
275276
case ProtocolMessageType.ReplayRequest: return 'ReplayRequest';
276277
case ProtocolMessageType.Pause: return 'PauseWriting';
277278
case ProtocolMessageType.Resume: return 'ResumeWriting';
279+
case ProtocolMessageType.KeepAlive: return 'KeepAlive';
278280
}
279281
}
280282

@@ -794,6 +796,8 @@ export class PersistentProtocol implements IMessagePassingProtocol {
794796
private _incomingMsgLastTime: number;
795797
private _incomingAckTimeout: any | null;
796798

799+
private _keepAliveInterval: any | null;
800+
797801
private _lastReplayRequestTime: number;
798802
private _lastSocketTimeoutTime: number;
799803

@@ -850,6 +854,11 @@ export class PersistentProtocol implements IMessagePassingProtocol {
850854
if (initialChunk) {
851855
this._socketReader.acceptChunk(initialChunk);
852856
}
857+
858+
// send a message every 5s
859+
this._keepAliveInterval = setInterval(() => {
860+
this._sendKeepAlive();
861+
}, 5000);
853862
}
854863

855864
dispose(): void {
@@ -861,6 +870,10 @@ export class PersistentProtocol implements IMessagePassingProtocol {
861870
clearTimeout(this._incomingAckTimeout);
862871
this._incomingAckTimeout = null;
863872
}
873+
if (this._keepAliveInterval) {
874+
clearInterval(this._keepAliveInterval);
875+
this._keepAliveInterval = null;
876+
}
864877
this._socketDisposables = dispose(this._socketDisposables);
865878
}
866879

@@ -982,7 +995,7 @@ export class PersistentProtocol implements IMessagePassingProtocol {
982995
break;
983996
}
984997
case ProtocolMessageType.Ack: {
985-
// nothing to do
998+
// nothing to do, .ack is handled above already
986999
break;
9871000
}
9881001
case ProtocolMessageType.Disconnect: {
@@ -1006,6 +1019,10 @@ export class PersistentProtocol implements IMessagePassingProtocol {
10061019
this._socketWriter.resume();
10071020
break;
10081021
}
1022+
case ProtocolMessageType.KeepAlive: {
1023+
// nothing to do
1024+
break;
1025+
}
10091026
}
10101027
}
10111028

@@ -1129,6 +1146,11 @@ export class PersistentProtocol implements IMessagePassingProtocol {
11291146
const msg = new ProtocolMessage(ProtocolMessageType.Ack, 0, this._incomingAckId, getEmptyBuffer());
11301147
this._socketWriter.write(msg);
11311148
}
1149+
1150+
private _sendKeepAlive(): void {
1151+
const msg = new ProtocolMessage(ProtocolMessageType.KeepAlive, 0, 0, getEmptyBuffer());
1152+
this._socketWriter.write(msg);
1153+
}
11321154
}
11331155

11341156
// (() => {

0 commit comments

Comments
 (0)