You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I've been working on porting Java implementation of EngineIO and SocketIO to Kotlin Multiplatform recently.
During the development and test process, I find two code logic bugs. I reported them in socketio/engine.io-client-java #119 and #120, but it seems that this repo hasn't been active for almost 3 years.
I reviewed the latest code of JS implementation, and the bugs are the same.
Bug of Socket's sendPacket and flush implementation
When we want to send a packet, we add it to writeBuffer and trigger flush, and we send all packets in writeBuffer to transport, and we remove this amount of packets from writeBuffer in onDrain.
But if we call send multiple times before onDrain is triggered, let's say 3 times, with pkt1, pkt2, pkt3, then we will call transport.send 3 times, with [pkt1], [pkt1, pkt2], and [pkt1, pkt2, pkt3], and that's definitely a wrong behavior.
protectedvoiddoClose() {
finalPollingself = this;
Emitter.Listenerclose = newEmitter.Listener() {
@Overridepublicvoidcall(Object... args) {
logger.fine("writing close packet");
self.write(newPacket[]{newPacket(Packet.CLOSE)});
}
};
if (this.readyState == ReadyState.OPEN) {
logger.fine("transport open - closing");
close.call();
} else {
// in case we're trying to close while// handshaking is in progress (engine.io-client GH-164)logger.fine("transport not open - deferring close");
this.once(EVENT_OPEN, close);
}
}
Hi, I've been working on porting Java implementation of EngineIO and SocketIO to Kotlin Multiplatform recently.
During the development and test process, I find two code logic bugs. I reported them in socketio/engine.io-client-java #119 and #120, but it seems that this repo hasn't been active for almost 3 years.
I reviewed the latest code of JS implementation, and the bugs are the same.
Bug of Socket's sendPacket and flush implementation
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/Socket.java#L696C1-L712C6
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/Socket.java#L617C1-L627C6
When we want to send a packet, we add it to writeBuffer and trigger flush, and we send all packets in writeBuffer to transport, and we remove this amount of packets from writeBuffer in onDrain.
But if we call send multiple times before onDrain is triggered, let's say 3 times, with pkt1, pkt2, pkt3, then we will call transport.send 3 times, with [pkt1], [pkt1, pkt2], and [pkt1, pkt2, pkt3], and that's definitely a wrong behavior.
Bug of Polling transport's close implementation
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/transports/Polling.java#L147C1-L167C6
https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/Transport.java#L83C1-L94C6
Actually if we call transport.close() while the polling transport is still opening,
EVENT_OPEN
won't be triggered, becausedoClose
will return immediately, andTransport.this.onClose()
will be called, thenreadyState
will beCLOSED
, and any further response of poll won't triggerEVENT_OPEN
, because code logic below:https://github.com/socketio/engine.io-client-java/blob/main/src/main/java/io/socket/engineio/client/transports/Polling.java#L109C1-L129C11
I think the problem is we shouldn't call
Transport.this.onClose()
inTransport.this.close()
, am I right?The text was updated successfully, but these errors were encountered: