Skip to content

Commit e808e68

Browse files
author
Loïc Mangeonjean
committed
fix: do not close whole websocket when v5 protocol is supported
1 parent 15c6ef8 commit e808e68

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/web-socket-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ export class WebSocketHandler implements WebSocketInterface {
106106
buff.writeUint8(this.CloseStream, 0);
107107
buff.writeUint8(this.StdinStream, 1);
108108
ws.send(buff);
109+
} else {
110+
ws.close();
109111
}
110-
ws.close();
111112
});
112113
// Keep the stream open
113114
return true;

src/web-socket-handler_test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,23 @@ describe('V5 protocol support', () => {
389389
});
390390
it('should handle closing stdin v5 protocol', () => {
391391
let sent: Buffer | null = null;
392+
let closed = false
392393
const ws = {
393394
protocol: 'v5.channel.k8s.io',
394395
send: (data) => {
395396
sent = data;
396397
},
397-
close: () => {},
398+
close: () => {
399+
closed = true
400+
},
398401
} as WebSocket;
399402
const stdinStream = new ReadableStreamBuffer();
400403
WebSocketHandler.handleStandardInput(ws, stdinStream);
401404
stdinStream.emit('end');
402405
expect(sent).to.not.be.null;
403406
expect(sent!.readUint8(0)).to.equal(255); // CLOSE signal
404407
expect(sent!.readUint8(1)).to.equal(0); // Stdin stream is #0
408+
expect(closed).to.equal(false)
405409
});
406410
});
407411

0 commit comments

Comments
 (0)