-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect closing of the client when the channel destroying #349
Labels
bug
Something isn't working
Comments
This happens due to the fact that when the
|
I slightly changed the error catching code, and here is the result: 12:54:05 W6 log destroy chanel { idClient: 193n, accountId: 4577, closeCount: 2 }
12:54:29 W6 log Emmiting on a destroyed client { idClient: 193n, accountId: 4577, closeCount: 4 } Changed codeClientclass Client {
static idClientN = 0n;
constructor() {
this.events = { close: [] };
this.eventId = 0;
this.streams = new Map();
this.streamId = 0;
this.idClient = Client.idClientN++;
}
...
emit(name, data) {
const packet = { event: --this.eventId, [name]: data };
const channel = channels.get(this);
if (channel === null) {
const { idClient, accountId } = this;
const closeCount = this.events.close.length;
console.log('Emmiting on a destroyed client', {idClient, accountId, closeCount});
for (const callback of this.events.close) callback();
//throw new Error('Emmiting on a destroyed client');
return;
}
if (!channel || !channel.connection) {
console.log(channel, this, [...channels]);
throw new Error(`Can't send metacom events to http transport`);
}
channel.send(packet);
}
...
} Chanel destroy() {
const { idClient, accountId } = this.client;
const closeCount = this.client.events.close.length;
console.log('destroy chanel', {idClient, accountId, closeCount});
for (const callback of this.client.events.close) callback();
channels.set(this.client, null);
if (!this.session) return;
sessions.delete(this.session.token);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
This issue occurs when using subscriptions. In some cases, the client instance does not close correctly when the channel is destroyed, and the close event does not happen. As a result, when trying to emit something to this client instance, we get an error, since there is no such key in the channels map.
To Reproduce
To confirm the problem, the destroy method in the Chanel class and the emit method in the Client class were modified:
Screenshots
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: