fix: mark the socket as closed when receiving a close/error message (#25180)

This commit is contained in:
Steven Luscher 2022-05-13 02:07:13 -07:00 committed by GitHub
parent 5948b6c741
commit e024806aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -4174,6 +4174,7 @@ export class Connection {
* @internal
*/
_wsOnError(err: Error) {
this._rpcWebSocketConnected = false;
console.error('ws error:', err.message);
}
@ -4181,6 +4182,7 @@ export class Connection {
* @internal
*/
_wsOnClose(code: number) {
this._rpcWebSocketConnected = false;
this._rpcWebSocketGeneration++;
if (this._rpcWebSocketHeartbeat) {
clearInterval(this._rpcWebSocketHeartbeat);

View File

@ -518,10 +518,36 @@ describe('Subscriptions', () => {
);
});
});
describe('then having the socket connection error', () => {
beforeEach(() => {
stubbedSocket.emit(
'error',
new Error('A bad thing happened to the socket'),
);
});
describe('making another subscription while disconnected', () => {
beforeEach(() => {
stubbedSocket.call.resetHistory();
setupListener(spy());
});
it('does not issue an RPC call', () => {
expect(stubbedSocket.call).not.to.have.been.called;
});
});
});
describe('then having the socket connection drop unexpectedly', () => {
beforeEach(() => {
stubbedSocket.emit('close');
});
describe('making another subscription while disconnected', () => {
beforeEach(() => {
stubbedSocket.call.resetHistory();
setupListener(spy());
});
it('does not issue an RPC call', () => {
expect(stubbedSocket.call).not.to.have.been.called;
});
});
describe('upon the socket connection reopening', () => {
let fatalPriorUnubscribe;
beforeEach(() => {