Skip to content

Commit 967590c

Browse files
committed
fix: availability can be read after close
Signed-off-by: Kevin Viglucci <[email protected]>
1 parent 0979ee1 commit 967590c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/rsocket-websocket-server/src/WebsocketDuplexConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class WebsocketDuplexConnection
5555
}
5656

5757
get availability(): number {
58-
return this.websocketDuplex.destroyed ? 0 : 1;
58+
return this.done ? 0 : 1;
5959
}
6060

6161
close(error?: Error) {

packages/rsocket-websocket-server/src/__tests__/WebsocketDuplexConnection.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ describe("WebsocketDuplexConnection", function () {
177177
new Error("WebsocketDuplexConnection: Socket closed unexpectedly.")
178178
);
179179
});
180+
181+
it("declares availability as 0", () => {
182+
// arrange
183+
const socketStub = mock<Duplex>();
184+
const multiplexerDemultiplexer = mock<
185+
Multiplexer & Demultiplexer & FrameHandler
186+
>();
187+
const frame = mock<Frame>();
188+
const connection = new WebsocketDuplexConnection(
189+
socketStub,
190+
frame,
191+
() => multiplexerDemultiplexer
192+
);
193+
194+
// act
195+
connection.close();
196+
197+
// assert
198+
expect(connection.availability).toEqual(0);
199+
});
180200
});
181201

182202
// describe("send()", () => {

0 commit comments

Comments
 (0)