-
Notifications
You must be signed in to change notification settings - Fork 844
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
Ack Callback and event handler not executed in the same order as received packets #950
Comments
@MarcoBrescianini Thanks. This was a leftover from when there was more complicated queueing going on. Now that that is cleaned up, this should be straightforward. Can you checkout the latest development branch? |
Yes I'll try the latest development branch, and i'll let you know |
Hi @nuclearace I've tried the latest commit on the development branch, and It worked. However, I get a runtime error whenever I try to emit another event from the same thread of execution of an ack callback. The execution flow is the following: This happens if client emits are performed on the main queue, and the SocketManager handle queue is not changed from the default one (main queue). Thread of execution doesn't leave the main queue, and you get a runtime exception because SocketAckManager struct is being mutated while it is already mutating. You can get more insights from the log attached: Simultaneous accesses to 0x6040000feec8, but modification requires exclusive access. In my humble opinion SocketAckManager should be modified to be a class, to avoid this exception. What do you think about it? |
Ah... Yeah I guess that makes sense |
@MarcoBrescianini The exclusive access issue should be fixed in development. Sorry it took so long, been busy with actual work stuff. |
Nice! Thanks man, have a good day! |
* development: update changelog Remove MARK: for websockets methods Use callbacks instead of delegate methods for Starscream Fix exclusive access issue Execute acks sync. Implement #950 Fixes build warnings caused by documentation issues. update starscream carthage
Scenario:
Client connected to a server via WebSocket.
Client is listening for event "bar".
Client emits a message "foo" waiting for ack callback.
Server processes "foo" message sent by client, it sends an ack, then emits a "bar" event.
Expected Behavior:
I expect that "foo" ack callback will be executed before "bar" handler.
Current Behavior:
Event handler is executed before ack callback
Context:
Detailed Description:
I noticed that anytime the SocketManager class receives any kind of packets, it submits a block onto its handleQueue asynchronously, asking a SocketIOClient to handle the parsed packet. If packet is an "event" kind, the client executes event handlers callbacks immediately; If the packet received is an "ack" kind, it delegates the packet handling operation to SocketAckManager, that it will submit a block asynchronously on the queue, provided as argument to "executeAck" method (in this case SocketManager's handleQueue), that will execute the ack's callback.
The chain of events I believe is happening is the following:
Proposed Solution:
Promote SocketAckManager to a class. Change "executeAck" and "timeoutAck" methods to execute ack callback synchronously. The reason why SocketAckManager must be modified to be a class, is that in case of re-entrant invocations in one of the "mutating" methods you get a runtime exception (i.e Simultaneous accesses to [...], but modification requires exclusive access).
I did this editing, and I noticed that the problem doesn't occur anymore.
Side Notes:
I don't have any experience with Swift whatsoever, and I didn't understand entirely Socket.IO library internals either. So, I don't know which side effects these changes could carry.
I'm pretty sure this strange behaviour is not caused by the server implementation, because our Android and Web clients don't seem to show the same behaviour.
You can find below a log where you can see the differences between what happens in the original library implementation and my changed version (sensitive data has been removed):
The text was updated successfully, but these errors were encountered: