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

Commonly used interface for http & ws breaks connections #458

Closed
mStirner opened this issue May 6, 2024 · 2 comments
Closed

Commonly used interface for http & ws breaks connections #458

mStirner opened this issue May 6, 2024 · 2 comments
Labels
bug Something that should not be like that component:devices

Comments

@mStirner
Copy link
Member

mStirner commented May 6, 2024

Alle Jahre wieder...

When a interface connection is used for http and alter for https, its break the websocket connection.
"RSV ... frame must be clear". This is due to the "keep-alive" handling in the iface.httpAgent():

if (agent.protocol === "http:" && !(headers?.upgrade === "websocket" && headers?.connection === "upgrade")) {
chunk = chunk.toString().replace(/connection:\s?close\r\n/i, "connection: keep-alive\r\n");
}

The agent is created, cached, and then the agent from the http request is returned:

if (this.cachedAgent) {
return this.cachedAgent;
}

There needs to be a way to check the URL for which the connection is used.


    iface.on("attached", () => {

        console.log("iface attacehd");
        let agent = iface.httpAgent();
        request(`http://${host}:${port}/socket.io/1/?t=${Date.now()}`, {
            agent
        }, (err, result) => {
            if (err) {

                console.error(err);
                process.exit(1);

            } else {

                let start = null;
                let wsp = result.body.toString().split(":")[0];

                console.log("WS GET", wsp)
                let ws = new WebSocket(`ws://${host}:${port}/socket.io/1/websocket/${wsp}`, {
                    agent
                });

Cause the trouble described above.
Add a option to the agent to unpipe everything from the upstream & re-create a new uncached agent?

@mStirner mStirner added component:devices bug Something that should not be like that labels May 6, 2024
@mStirner
Copy link
Member Author

mStirner commented May 6, 2024

Tip

Workaround: Create 2 interfaces with the same host/port settings.
Use one dedicated for HTTP and one for WebSocket connections.

@mStirner
Copy link
Member Author

Use new interface method .bridge() to create new sockets.
In v4 the iface.httpAgent(),iface.httpsAgent() uses this under the hood and no action/workaround is needed anymore.

See mStirner@fe8c2a9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that should not be like that component:devices
Projects
None yet
Development

No branches or pull requests

1 participant