Skip to content
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

bug: when we use cluster adapter on linux (client A send message to Client B with callback ) #4163

Closed
introspection3 opened this issue Nov 11, 2021 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@introspection3
Copy link

Describe the bug
bug: when we use cluster adapter on linux (windows ok) (client A send Client B with callback ),will go wrong
at BroadcastOperator.emit (/opt/fastnat/index.js:162511:19)
at RemoteSocket.emit (/opt/fastnat/index.js:162604:30)
at /opt/fastnat/index.js:729:30
at processTicksAndRejections (node:internal/process/task_queues:96:5)
2021-11-09T21:36:53.490 ERROR default 3944986 :==> Error: Callbacks are not supported when broadcasting
at BroadcastOperator.emit (/opt/fastnat/index.js:162511:19)
at RemoteSocket.emit (/opt/fastnat/index.js:162604:30)
at /opt/fastnat/index.js:729:30
at processTicksAndRejections (node:in
To Reproduce

Please fill the following code example:

Socket.IO server version: x.y.z

"socket.io": "^4.1.3",
"socket.io-client": "^4.1.3",

on server

     socket.on(commandType.P2P_REQUEST_OPEN, async(data, fn) => {
        let targetClientId = data.targetClientId;
        let result = false;
        let info = '';
        let allSockets = await defaultNS.fetchSockets();
        let targetSocket = allSockets.find((value, index, array) => {
            return value.handshake.auth.clientId === targetClientId;
        });

        if (targetSocket != null) {
            result = true;
            logger.trace('start to notify targe socket to open p2p');
            //crash  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            targetSocket.emit(commandType.P2P_REQUEST_OPEN, data, (ret) => {
                fn(ret);
            });
        } else {
            info = `targetTunnelId's client is not online:targetClientId=` + targetClientId;
            fn({ success: result, data: data, info: info });
        }

    });
@introspection3 introspection3 added the bug Something isn't working label Nov 11, 2021
@introspection3 introspection3 changed the title bug: when we use cluster adapter on linux (client A send Client B with callback ) bug: when we use cluster adapter on linux (client A send message to Client B with callback ) Nov 11, 2021
@darrachequesne
Copy link
Member

darrachequesne commented Nov 13, 2021

Yes, this is expected.

Related: #1811

darrachequesne added a commit to socketio/socket.io-adapter that referenced this issue Mar 29, 2022
Tests will be added in the parent repository.

Related:

- socketio/socket.io#1811
- socketio/socket.io#4163
darrachequesne added a commit that referenced this issue Mar 31, 2022
Syntax:

```js
io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});
```

The adapter exposes two additional methods:

- `broadcastWithAck(packets, opts, clientCountCallback, ack)`

Similar to `broadcast(packets, opts)`, but:

* `clientCountCallback()` is called with the number of clients that
  received the packet (can be called several times in a cluster)
* `ack()` is called for each client response

- `serverCount()`

It returns the number of Socket.IO servers in the cluster (1 for the
in-memory adapter).

Those two methods will be implemented in the other adapters (Redis,
Postgres, MongoDB, ...).

Related:

- #1811
- #4163
- socketio/socket.io-redis-adapter#445
darrachequesne added a commit to socketio/socket.io-cluster-adapter that referenced this issue Apr 28, 2022
This feature was added in `socket.io@4.5.0`:

```js
io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});
```

Thanks to this change, it will now work with multiple Socket.IO
servers.

Related: socketio/socket.io#4163
@darrachequesne
Copy link
Member

This use case is now supported by socket.io@4.5.0 and @socket.io/cluster-adapter@0.2.0. Thanks!

@darrachequesne darrachequesne added enhancement New feature or request and removed bug Something isn't working labels Apr 28, 2022
@darrachequesne darrachequesne added this to the 4.5.0 milestone Apr 28, 2022
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
Syntax:

```js
io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});
```

The adapter exposes two additional methods:

- `broadcastWithAck(packets, opts, clientCountCallback, ack)`

Similar to `broadcast(packets, opts)`, but:

* `clientCountCallback()` is called with the number of clients that
  received the packet (can be called several times in a cluster)
* `ack()` is called for each client response

- `serverCount()`

It returns the number of Socket.IO servers in the cluster (1 for the
in-memory adapter).

Those two methods will be implemented in the other adapters (Redis,
Postgres, MongoDB, ...).

Related:

- socketio#1811
- socketio#4163
- socketio/socket.io-redis-adapter#445
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants