Comments (2)
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:
- 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. - 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. - 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. - Have 2 distinct errors
Channel is destroyed
(if !channel) andChannel does not support events
( if !channel.connection)
from metacom.
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)
- Add index.html doesn't work on WIndows
- Browser version of events makes self invokes (recursion) HOT 1
- Optimize `Client` class HOT 2
- Streams: save todos from sources
- New class structure HOT 2
- Remove `window` dependency for enhanced platform compatibility
- Custom packet type for plugin system
- Fix eslint warnings HOT 1
- Extract protocol serialization/deserialization and expose it
- Decompose Client and Transport
- Invalid event packets handling on client (server) HOT 1
- Log HTTP 200
- Move semaphore from metacom to impress
- Reorganize network connectivity tracking HOT 3
- Implement websocket without dependencies
- Use nodejs 21 websocket client
- Refactor frame parsing
- Refactor websocket server interface
- Add websocket server test HOT 1
- Move from ws to custom solution
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metacom.