Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

transports-uws/polling.js: TypeError: res.onData is not a function #637

Closed
bogdankatishev opened this issue Jan 17, 2022 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@bogdankatishev
Copy link

Hello,

When testing uws on our socket server, we found a issue. I have configured a socket-io client to only do polling as transport, but when sending the request from socket-io client to the socket-io server, i found this in my socket server console:

node_modules/engine.io/build/transports-uws/polling.js:133
        res.onData((chunk, isLast) => {
            ^
TypeError: res.onData is not a function

And then it crashes the node server.

@bogdankatishev bogdankatishev added the bug Something isn't working label Jan 17, 2022
@darrachequesne
Copy link
Member

darrachequesne commented Jan 17, 2022

Hi! That sounds really weird. The source code is here:

res.onAborted(onClose);
res.onData((chunk, isLast) => {
chunks.push(Buffer.from(chunk));
contentLength += Buffer.byteLength(chunk);
if (contentLength > this.maxHttpBufferSize) {
this.onError("payload too large");
res.writeStatus("413 Payload Too Large");
res.end();
return;
}
if (isLast) {
onEnd();
}
});

The question is: how can res.onData() fail whereas res.onAborted() above succeeds?

Are you able to reproduce? I wasn't with the following code:

Server

const { App } = require("uWebSockets.js");
const { Server } = require("socket.io");

const app = new App();
const io = new Server();

io.attachApp(app);

io.on("connection", (socket) => {
  setInterval(() => {
    socket.emit("wut", () => {
      console.log("acked!");
    });
  }, 1000);

  socket.on("woot", (cb) => {
    cb();
  });
});

app.listen(4000, (token) => {
  if (!token) {
    console.warn("port already in use");
  }
});

Client

const io = require("socket.io-client");

const socket = io("http://localhost:4000", {
  transports: ["polling"]
});

socket.on("connect", () => {
  console.log(`connect ${socket.id}`);
});

setInterval(() => {
  socket.emit("woot", () => {
    console.log("acked!");
  });
}, 1000);

socket.on("wut", (cb) => {
  cb();
});

darrachequesne added a commit that referenced this issue Jan 18, 2022
When binding to an uWebSockets.js application, the server could crash
with the following error:

```
TypeError: res.onData is not a function
    at Polling.onDataRequest (build/transports-uws/polling.js:133:13)
    at Polling.onRequest (build/transports-uws/polling.js:47:18)
    at callback (build/userver.js:80:56)
```

Related: #637
@darrachequesne
Copy link
Member

OK, so I've finally able to reproduce. It should be fixed by 45112a3, included in engine.io-client@6.1.2.

Thanks for raising the issue! Please reopen if needed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants