Skip to content

SocketIOClient Triggers connect event too early #1194

Open
@nikolaybotev

Description

@nikolaybotev

The Swift socket.io client deviates from the behavior of the reference javascript socket.io client when it comes to firing connect events.

connect events are fired too early, before the server has acknowledged the connection with a special connect packet. If the server performs non-trivial work (such as authenticating the new connection) before acknowledging it (e.g. in namespace middleware), and only registers socket event listeners in its own subsequent 'connect' event for the socket (as shown in most socket.io documentation examples), and the client sends a message to the server as soon as it receives its own socket connect event, then there is a very tangible race condition between the client's and the server's connect events. If the client's connect event happens before the server's connect event then there is a chance that the server will never see the messages sent from the client's connect handler because the server has not had a chance to install its client message listeners yet (in its own connect handler).

This is demonstrated very clearly in https://github.com/nikolaybotevb/socket.io-client-swift-connect-event-bug, including a comparison to the javascript socket.io client, which works correctly under such scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions