fix forceful close workflow
This commit is contained in:
@@ -276,6 +276,7 @@ export class WebsocketClient extends EventEmitter {
|
|||||||
|
|
||||||
public closeAll(force?: boolean) {
|
public closeAll(force?: boolean) {
|
||||||
const keys = this.wsStore.getKeys();
|
const keys = this.wsStore.getKeys();
|
||||||
|
this.logger.info(`Closing all ws connections: ${keys}`);
|
||||||
keys.forEach((key) => {
|
keys.forEach((key) => {
|
||||||
this.close(key, force);
|
this.close(key, force);
|
||||||
});
|
});
|
||||||
@@ -441,6 +442,10 @@ export class WebsocketClient extends EventEmitter {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
if (
|
||||||
|
this.wsStore.getConnectionState(wsKey) !==
|
||||||
|
WsConnectionStateEnum.CLOSING
|
||||||
|
) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`${context} due to unexpected response error: "${
|
`${context} due to unexpected response error: "${
|
||||||
error?.msg || error?.message || error
|
error?.msg || error?.message || error
|
||||||
@@ -448,6 +453,11 @@ export class WebsocketClient extends EventEmitter {
|
|||||||
{ ...loggerCategory, wsKey, error }
|
{ ...loggerCategory, wsKey, error }
|
||||||
);
|
);
|
||||||
this.executeReconnectableClose(wsKey, 'unhandled onWsError');
|
this.executeReconnectableClose(wsKey, 'unhandled onWsError');
|
||||||
|
} else {
|
||||||
|
this.logger.info(
|
||||||
|
`${wsKey} socket forcefully closed. Will not reconnect.`
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.emit('error', error);
|
this.emit('error', error);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
getSilentLogger,
|
getSilentLogger,
|
||||||
waitForSocketEvent,
|
waitForSocketEvent,
|
||||||
WS_OPEN_EVENT_PARTIAL,
|
WS_OPEN_EVENT_PARTIAL,
|
||||||
|
fullLogger,
|
||||||
} from '../ws.util';
|
} from '../ws.util';
|
||||||
|
|
||||||
describe('Private Spot V1 Websocket Client', () => {
|
describe('Private Spot V1 Websocket Client', () => {
|
||||||
@@ -30,6 +31,7 @@ describe('Private Spot V1 Websocket Client', () => {
|
|||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
wsClient = new WebsocketClient(
|
wsClient = new WebsocketClient(
|
||||||
wsClientOptions,
|
wsClientOptions,
|
||||||
|
// fullLogger
|
||||||
getSilentLogger('expectSuccess')
|
getSilentLogger('expectSuccess')
|
||||||
);
|
);
|
||||||
logAllEvents(wsClient);
|
logAllEvents(wsClient);
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ describe('Public Unified Margin Websocket Client (Perps - USDC)', () => {
|
|||||||
wsClient.connectPublic();
|
wsClient.connectPublic();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
wsClient.closeAll(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should open a public ws connection', async () => {
|
it('should open a public ws connection', async () => {
|
||||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||||
try {
|
try {
|
||||||
@@ -42,6 +38,8 @@ describe('Public Unified Margin Websocket Client (Perps - USDC)', () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toBeFalsy();
|
expect(e).toBeFalsy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wsClient.closeAll(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: are there USDC topics? This doesn't seem to work
|
// TODO: are there USDC topics? This doesn't seem to work
|
||||||
|
|||||||
Reference in New Issue
Block a user