Giter VIP home page Giter VIP logo

Comments (2)

nechaido avatar nechaido commented on September 26, 2024 1

This happens due to the fact that when the channel is destroyed, no close event is emitted on the client, as we expect the other side to reconnect to the same client IIUC. Possible solutions:

  1. Add intermediary reconnecting event and status to the client and check it when sending the event. We would need a proper reconnection strategy and event buffer for this. So we do not lose any data.
  2. Treat this situation as an exception so that users can handle it themselves. Add NULL-ish connection (Symbol.for('DESTROYED-CONNECTION')) and serve it to channels Map on connection.destroy(). We would still need to collect it garbage somehow.
  3. Leave it as it is, but change the error message to Channel can't send events. And add the clarification to the documentation that this error will occur if channel` is not ready or does not support events.
  4. Have 2 distinct errors Channel is destroyed (if !channel) and Channel does not support events ( if !channel.connection)

from metacom.

MarhiievHE avatar MarhiievHE commented on September 26, 2024

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 code

Client

class 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);
  }

from metacom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.