Skip to content

Commit

Permalink
fix: do not close whole websocket when v5 protocol is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Dec 18, 2024
1 parent 15c6ef8 commit e808e68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/web-socket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ export class WebSocketHandler implements WebSocketInterface {
buff.writeUint8(this.CloseStream, 0);
buff.writeUint8(this.StdinStream, 1);
ws.send(buff);
} else {
ws.close();
}
ws.close();
});
// Keep the stream open
return true;
Expand Down
6 changes: 5 additions & 1 deletion src/web-socket-handler_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,23 @@ describe('V5 protocol support', () => {
});
it('should handle closing stdin v5 protocol', () => {
let sent: Buffer | null = null;
let closed = false
const ws = {
protocol: 'v5.channel.k8s.io',
send: (data) => {
sent = data;
},
close: () => {},
close: () => {
closed = true
},
} as WebSocket;
const stdinStream = new ReadableStreamBuffer();
WebSocketHandler.handleStandardInput(ws, stdinStream);
stdinStream.emit('end');
expect(sent).to.not.be.null;
expect(sent!.readUint8(0)).to.equal(255); // CLOSE signal
expect(sent!.readUint8(1)).to.equal(0); // Stdin stream is #0
expect(closed).to.equal(false)
});
});

Expand Down

0 comments on commit e808e68

Please sign in to comment.