Skip to content

HTTP request is sent twice in Node app #1416

Closed
@b1nks

Description

@b1nks

I'm using unit:node Docker image and I encountered double sending of http requests.

Looks like a bug, but I'm not qualified enough to dive deeper into the problem.

The situation can be repeated on the simplest configuration:

  • Use a pure image unit:node, basic Unit configuration and copy there a .js file with sending an http request from anywhere
const http = require("unit-http");

const options = {
  hostname: "<your hostname>",
  port: 80,
  path: "/<your path>",
  method: "GET",
};

const req = http.request(options, (res) => {
  let responseData = "";

  res.on("data", (chunk) => {
    responseData += chunk;
  });

  res.on("end", () => {
    console.log("Response:", responseData);
  });
});

req.on("error", (error) => {
  console.error("Error:", error);
});

req.end();

const server = http.createServer();

server.listen();
  • When we launch the container we will see one line in the logs, but when we look at the logs of the target server we will actually see two requests

Metadata

Metadata

Assignees

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