socketio / socketio/socket.io

IOS 15.5 Cannot Connect (Client & Server 4.5.1)

Open
#4,397 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

Describe the bug
Cannot connect with IOS 15.5 Devices

To Reproduce

Socket.IO server version: 4.5.1

Server

export const initSocketIO = (server: any) => {
  const io = require("socket.io")(server);

  io.on("connection", async (socket: Socket) => {
    logger.info(`user is connecting...`);

    let token = socket.handshake.query.token;
    let applicationId = socket.handshake.query.applicationId;

    .....

Socket.IO client version: 4.5.1

Client

  useEffect(() => {

    if (socket) {
      socket.removeAllListeners();

      if (socket.listeners("connect").length === 0) {
        socket.on('connect', () => {
          console.log('connected')
          dispatch(setSupportStatus(true));
        })
      }

      if (socket.listeners("message").length === 0) {
        socket.on('message', (data: any) => {
          console.log(data);
          if (data.chatRoomId == support.selectedChatRoom?.id) {
            dispatch(addActiveChat(data));
          } else {
            //create notification badge
            dispatch(setNewMessage({ id: data.chatRoomId, value: true }));
          }
        })
      }

      if (socket.listeners("close-chat-room").length === 0) {
        socket.on('close-chat-room', (id: string) => {
          dispatch(closeChatRoom(id));
        })
      }

      if (socket.listeners("disconnect").length === 0) {
        socket.on('disconnect', (data: any) => {
          console.log('disconnected');
          dispatch(setSupportStatus(false));
        })
      }
    }

    if (socket && !support.connected) {
      socket.connect();
      getActiveSupportTickets();
    }
  }, [dispatch, support.connected, support.selectedChatRoom?.id, getActiveSupportTickets, socketReady]);

  useEffect(() => {
    if (support.userId && support.token && support.applicationId) {
      setSocket(io(socketIoServer,
        {
          transports: ['websocket'],
          query: {
            token: support.token,
            applicationId: support.applicationId
          }
        }));
      setSocketReady(true);
    }
  }, [support.applicationId, support.token, support.userId]);

The code does not even get into io.on("connection",..., it stopped by the error even before getting into the connection event.

Expected behavior
A clear and concise description of what you expected to happen.

I expect IOS devices to be able to connect with my server.

Platform:

  • Device: All IOS Devices 15.5
  • OS: IOS 15.5

Additional context
Add any other context about the problem here.

The Error

The error from client:

[Error] WebSocket connection to 'wss://support.xxxxxx.com/socket.io/?token=xxxxx&applicationId=xxxxxx&EIO=4&transport=websocket' failed: There was a bad response from the server.

The error from the server:

2022-06-19T04:10:44.809Z engine handshaking client "KddXP_t6guQ2dxHwAABK" 
2022-06-19T04:10:44.809Z socket.io:server incoming connection with id KddXP_t6guQ2dxHwAABK Node.js

2022-06-19T04:10:46.125Z socket.io:client no namespace joined yet, close the client 
2022-06-19T04:10:46.125Z socket.io:client forcing transport close 
2022-06-19T04:10:46.125Z socket.io:client client close with reason forced close 
2022-06-19T04:10:46.125Z socket.io:client client close with reason forced server close Node.js

2022-06-19T04:10:50.706Z engine handshaking client "Y_yOM8oTDtT8sgntAABL" 
2022-06-19T04:10:50.706Z socket.io:server incoming connection with id Y_yOM8oTDtT8sgntAABL Node.js

2022-06-19T04:10:52.615Z socket.io:client no namespace joined yet, close the client 
2022-06-19T04:10:52.615Z socket.io:client forcing transport close 
2022-06-19T04:10:52.615Z socket.io:client client close with reason forced close 
2022-06-19T04:10:52.615Z socket.io:client client close with reason forced server close

The error repeated as the client keeps trying to re-connect.

Is is fine on Android Devices


Github Repo To Test

I have setup the github repo for testing the socket.io-client using dummy user (https://github.com/AlvinStefanus/socket).


Polling Connection Works

The polling connection works fine on iOS devices, but not websocket connection.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked socket.io-client reproduction repository and compare its websocket and polling setup on iOS 15.5. Reproduce the failed websocket handshake, using the client and server snippets plus the reported Engine.IO logs; done means identifying a project change that allows iOS websocket connections while preserving the working polling connection.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, typescript
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.