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

Client creates a new connection when it reconnects to one of the namespaces. #741

Open
aperfilyev opened this issue May 5, 2023 · 1 comment
Labels

Comments

@aperfilyev
Copy link

aperfilyev commented May 5, 2023

Describe the bug
Let's imagine that we open two sockets to the same path but with different namespaces. Here we see only one connection with the multiplex. Everything is OK.
Next, we will disconnect from one of the sockets, and after some time we will open it again. I expect no new connection will be created.

To Reproduce

Socket.IO java client version: 1.x

Client

@Test
public void namespacesTest() throws Exception {
    IO.Options opts = new IO.Options();
    opts.forceNew = false;
    opts.path = "/path";
    Socket socket1 = IO.socket(uri() + "/nsp1", opts);
    Socket socket2 = IO.socket(uri() + "/nsp2", opts);
    socket1.open();
    socket2.open();
    
    assertThat(socket1.io(), equalTo(socket2.io())); // passes as expected
    socket2.close();
    
    Socket socket3 = IO.socket(uri() + "/nsp2", opts);
    socket3.open();
    
    assertThat(socket1.io(), equalTo(socket3.io())); // fails as not expected
    
    socket1.close();
    socket3.close();
}

Expected behavior

Single connection is reused

@aperfilyev aperfilyev added the bug label May 5, 2023
@momocow
Copy link

momocow commented Jan 2, 2025

Just found something in the document, it might give you some clues of the behavior.

Please note that multiplexing will be disabled in the following cases:

  • multiple creation for the same namespace
const socket1 = io();
const socket2 = io(); // no multiplexing, two distinct WebSocket connections

https://socket.io/docs/v4/namespaces/#client-initialization

It says "multiple creation" regardless of connection state, opened or closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants