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

Nodejs http server is processing concurrently the pipelined requests that have unsafe methods #50850

Open
ribeirotomas1904 opened this issue Nov 22, 2023 · 0 comments

Comments

@ribeirotomas1904
Copy link

Version

v20.9.0

Platform

Linux pc 5.15.0-88-generic #98~20.04.1-Ubuntu SMP Mon Oct 9 16:43:45 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

http

What steps will reproduce the bug?

const net = require("node:net");
const http = require("node:http");

const sleep = (seconds) => new Promise(resolve => setTimeout(resolve, seconds * 1000));

http.createServer(async (req, res) => {
    if (req.url === "/first") {
        await sleep(3);
    }

    if (req.url === "/second") {
        await sleep(0);
    }

    console.log(req.url);

    res.end(req.url);
}).listen(3000, () => {
    const socket = net.createConnection(3000, "localhost", () => {
        socket.write(
            "POST /first HTTP/1.1\r\n" +
            "Host: localhost:3000\r\n" +
            "\r\n" +
            "POST /second HTTP/1.1\r\n" +
            "Host: localhost:3000\r\n" +
            "\r\n"
        );
    });
});

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

since the requests are using unsafe methods, the first request should be processed entirely before processing the second request

What do you see instead?

the second request prints to the console before the first request

Additional information

from the HTTP/1.1 spec: "A server MAY process a sequence of pipelined requests in parallel if they all have safe methods" (from https://httpwg.org/specs/rfc9112.html#pipelining)

about safe methods: https://httpwg.org/specs/rfc9110.html#safe.methods
about "MAY": https://www.rfc-editor.org/rfc/rfc2119.html

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

1 participant