question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Volatile not working from server to client with binary data

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
darrachequesnecommented, Sep 8, 2021

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

3reactions
darrachequesnecommented, Nov 16, 2021

@brako zut, you are right. This should be finally fixed by https://github.com/socketio/socket.io-adapter/commit/88eee5948aba94f999405239025f29c754a002e2, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Emitting events | Socket.IO
Volatile events are events that will not be sent if the underlying connection is not ready (a bit like UDP, in terms of...
Read more >
Java Concurrency - Volatile, Final and Atomics @ https ...
CAUTION: Volatile variables do not provide any atomicity. For example, the method is not guaranteed to flip the value of the field. There...
Read more >
Netty binary data not flush out until 0x0a - Stack Overflow
My netty server application needs to reply to the client with binary data, but it seems flush out only when 0x0a is reached....
Read more >
Socket.IO 3 - Best HTTP/2 Documentation
IO server implementation binds to the /socket.io/ path, and the client going to append it to the uri if the ... Binary data...
Read more >
Understanding "volatile" qualifier in C | Set 1 (Introduction)
We think that the main reason for this is due to not having real-world use-case of a 'volatile' variable in typical C programs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found