SocketIOClient-Unreal icon indicating copy to clipboard operation
SocketIOClient-Unreal copied to clipboard

OnFail callback is not called if socket.io server rejects connection

Open alexeychikk opened this issue 3 years ago • 2 comments

UE5 master version of the library I implemented authentication in my socket.io server that rejects connections without authorization token in headers. When server rejects connection, OnFail callback is not called. This is 100% not the issue on my socket.io server because it is tested with node.js version of socket.io-client library. image

alexeychikk avatar Aug 03 '22 18:08 alexeychikk

Looking at the lib implementation https://github.com/getnamo/SocketIOClient-Unreal/blob/d942304e7fc8ccc65cd78bb1c116b6ed334632b0/Source/SocketIOLib/Private/internal/sio_client_impl.cpp#L453

it appears it tries reconnection automatically instead of failing if you have reconnection attempts left (default is infinity), check that you receive OnConnectionProblems callback instead?

If you want the fail callback, set MaxReconnectionAttempts to 0 before connecting.

getnamo avatar Aug 04 '22 17:08 getnamo

@getnamo Thanks for the quick answer, but it doesn't help. I tried 0 MaxReconnectionAttempts, I tried 1, nothing seem to work. image

The above blueprint prints nothing.

My server rejects anuthorized connection attempt but I don't receive any callbacks. If I use Postman's socket.io client or socket.io-client npm package - I receive connection error. Here is an example of my socket.io authorization middleware:

  middleware = async (
    socket: Socket,
    next: (err?: Error | undefined) => void,
  ) => {
    try {
      await this.authenticateSocket(socket);
      next();
    } catch (err) {
      if (err instanceof UnauthorizedException) {
        this.logger.debug(err);
        return next(err);
      }
      this.logger.error(err);
      next(new InternalServerErrorException());
    }
  };

In UE output logs I see the following:

SocketIO: SocketIO None disconnected from namespace: /
SocketIO: SocketIO Disconnected Invalid reason: CLOSE_REASON_NORMAL

but still, callbacks are not fired.

P.S. I would really like to help fixing this but my c++ knowledge is very limited.

alexeychikk avatar Aug 04 '22 20:08 alexeychikk