Skip to content

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

Open
@ribeirotomas1904

Description

@ribeirotomas1904

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions