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

Volatile not working from server to client with binary data #3919

Closed
sergmister opened this issue May 13, 2021 · 8 comments
Closed

Volatile not working from server to client with binary data #3919

sergmister opened this issue May 13, 2021 · 8 comments
Labels
bug Something isn't working
Milestone

Comments

@sergmister
Copy link

Describe the bug
Sending a volatile event from the client (Chrome) to Node with binary data works fine. Sending a volatile event from Node to the client with binary data does not work. Sending binary data without volatile works, sending non binary data with volatile works.

To Reproduce

Socket.IO server version: 4.1.1

Server

import { createServer } from "http";
import { Server, Socket } from "socket.io";

const httpServer = createServer({});

const io = new Server(httpServer, {
  cors: {
    origin: "http://localhost:8080",
    methods: ["GET", "POST"],
  },
});

io.on("connection", (socket) => {
  socket.on("some event", (data) => {
    console.log(data);
  });

  setTimeout(() => {
    socket.volatile.emit("some event", "hello");
    // socket.volatile.emit("some event", new ArrayBuffer(10));
  }, 1000);
});

httpServer.listen(3000);

Socket.IO client version: 4.1.1

Client

import { io } from "socket.io-client";

this.socket = io("http://localhost:3000");

    this.socket.on("some event", (data) => {
      console.log(data);
    });

    setTimeout(() => {
      this.socket.volatile.emit("some event", new ArrayBuffer(10));
    }, 1000);

works fine, changing the server code:

  setTimeout(() => {
    // socket.volatile.emit("some event", "hello");
    socket.volatile.emit("some event", new ArrayBuffer(10));
  }, 1000);

and the client receives nothing

Expected behavior
The client receives the binary data.

Platform:

  • OS: Linux 5.10
  • Node 15.14.0
@sergmister sergmister added the bug Something isn't working label May 13, 2021
@BrendanAnnable
Copy link

I can confirm this bug, and just encountered it when upgrading from socket.io v2 to v4.

It appears to send non-binary data just fine, and it will even send the non-binary parts of the same message just fine, including binary placeholder objects. But the binary packets which correspond to those placeholder objects appear to be never sent.

@lemonad
Copy link

lemonad commented Sep 5, 2021

I also ran into this problem when trying to use volatile. I'm using socket.io version 4.2.0.

@darrachequesne
Copy link
Member

I could indeed reproduce the issue. We will publish a fix as soon as possible.

darrachequesne added a commit that referenced this issue Sep 9, 2021
The binary attachments of volatile packets were discarded (only the
header packet was sent) due to a bug introduced by [1].

Related: #3919

[1]: dc381b7
@refeed
Copy link

refeed commented Oct 21, 2021

I just upgraded my app's socketio to the latest version (4.3.1) and still having this issue

@alexfrs69
Copy link

alexfrs69 commented Oct 22, 2021

Same issue here, tested with Uint8Array (protobuf), and Buffer.from (same as unit test) server to client volatile.emit() is still broken.

darrachequesne added a commit to socketio/socket.io-fiddle that referenced this issue Oct 27, 2021
@darrachequesne
Copy link
Member

This should be fixed by dc81fcf, included in socket.io@4.3.1.

@refeed I cannot reproduce: https://github.com/socketio/socket.io-fiddle/tree/issues/socket.io/3919, could you please check?

@darrachequesne darrachequesne added this to the 4.3.1 milestone Oct 27, 2021
@brako
Copy link

brako commented Nov 15, 2021

Thanks, the problem occurs when we send volatile data directly with the server (working fine with the socket )

setInterval(() => {
    io.volatile.emit("test", Buffer.from([1,2,3]));
  }, 1000);

You won't receive the data with the client.

darrachequesne added a commit to socketio/socket.io-adapter that referenced this issue Nov 16, 2021
The binary attachments of volatile packets were discarded (only the
header packet was sent) due to a bug introduced in [1].

Note: the `wsPreEncoded` option is removed by this commit, as I wasn't
able to find an elegant (read: non explosive) way to keep it.

[1]: 5579d40

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

@brako zut, you are right. This should be finally fixed by socketio/socket.io-adapter@88eee59, included in socket.io-adapter@2.3.3 (which should be included by latest socket.io by transitivity).

I added a test case here, to prevent any regression in the future.

Please reopen if needed.

dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
The binary attachments of volatile packets were discarded (only the
header packet was sent) due to a bug introduced by [1].

Related: socketio#3919

[1]: socketio@aafc3d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants