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

Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer when using with Socket.io #705

Closed
tahayk opened this issue Feb 16, 2022 · 7 comments

Comments

@tahayk
Copy link

tahayk commented Feb 16, 2022

Hey
I'm trying to use uWebSockets with Socket.io,
but I keep getting this error, and I noticed that it only happens when I use Safari:

node:buffer:254
  TypedArrayPrototypeSet(target, source, targetStart);
  ^

TypeError: Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer
    at Buffer.set (<anonymous>)
    at _copyActual (node:buffer:254:3)
    at Function.concat (node:buffer:562:12)
    at onEnd (/Users/.../node_modules/engine.io/build/transports-uws/polling.js:126:32)
    at /Users/tahayk/.../node_modules/engine.io/build/transports-uws/polling.js:143:17

Node.js v17.0.1

Here is the example I used:

server.js:

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

const app = new App();
const io = new Server({ cors: {
        origin: "*",
        methods: ["GET", "POST", "PUT"]
    }});

io.attachApp(app);

io.on("connection", (socket) => {
    // ...
});

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

demo.html

<!doctype html>
<html>
<head>
    <title>Socket.IO uWS</title>
</head>
<script src="node_modules/socket.io/client-dist/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
    $(function () {
        var socket = io(
            'ws://127.0.0.1:9000',
            {
                // transports: ["websocket"] // ----> it works if you add this
            });

        socket.onAny((eventName, ...args) => {
            console.log("received event: " + eventName);
        });
    });
</script>
<body>
</body>
</html>

Any idea about this issue ?
Thanks.

@e3dio
Copy link
Contributor

e3dio commented Feb 16, 2022

You can see the error is in engine.io/build/transports-uws/polling.js so you need to open issue in engine.io library

@ghost ghost closed this as completed Feb 16, 2022
@e3dio
Copy link
Contributor

e3dio commented Feb 17, 2022

@tahayk They are doing this wrong on this line https://github.com/socketio/engine.io/blob/a463d268ed90064e7863679bda423951de108c36/lib/transports-uws/polling.ts#L158 They are trying to concat Buffer views of arrayBuffers that are already gone, need to make copy

@e3dio
Copy link
Contributor

e3dio commented Feb 17, 2022

Buffer.from(arrayBuffer).copy(allocatedBuffer, offset)

@ghost
Copy link

ghost commented Feb 17, 2022

That's kind of interesting that they've actually built polling on uws http and are using the pub sub features. That means we've won, they have adopted our features and our API.

Compare this with 2016 when we adopted their interfaces and acted like a drop in module for their shitty API. That's a milestone since the NPM shitfest days.

@e3dio
Copy link
Contributor

e3dio commented Feb 18, 2022

I added PR to fix Socket.io issue here socketio/engine.io#642 as described here socketio/socket.io#4281 (comment)

@e3dio
Copy link
Contributor

e3dio commented Feb 23, 2022

@tahayk they just merged PR and released new version, that should be fixed for you

@tahayk
Copy link
Author

tahayk commented Feb 23, 2022

@e3dio thank you very much for your help

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

No branches or pull requests

2 participants