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

Data is lost in messages between Primary (aka Master) to Workers messaging (Cluster Mode) #45053

Closed
MatanYemini opened this issue Oct 18, 2022 · 3 comments

Comments

@MatanYemini
Copy link

Version

v16.17.1

Platform

20.04.1-Ubuntu x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Send POST / PUT / PATCH API with Content-Length that is bigger than 80KB running with Cluster Mode (using the standard cluster mode configuration as described: https://nodejs.org/dist/latest-v16.x/docs/api/cluster.html)

I was using Express and Body-Parser middleware, but I have debugged it inside, indicating that the issue is in the internal messaging between master (primary alias) to workers. The expected size of the body is less than the received size (after chunk aggregation).

The inequality happens ONLY with cluster mode enabled, if I am not using it, it is just working (without touching anything else).

I have tried several encodings to make sure it is not related - and got the same on every type of encoding.

95KB in body example (using application/json type):

  • The chunks in the parser without cluster mode - 65KB, 30KB
  • The chunks in the parser with cluster mode - 65KB, 2KB

Client ALWAYS showing the correct Content Length

Please direct me which more information you would like to get.

Saw a PR that was solving something similar: #13778

Thanks

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

Always.

As mentioned above:

Send POST / PUT / PATCH API with Content-Length that is bigger than 80KB running with Cluster Mode (using the standard cluster mode configuration as described: https://nodejs.org/dist/latest-v16.x/docs/api/cluster.html)

I have ran it using express and the default body-parser (that uses raw-body lib behind)

What is the expected behavior?

Cluster mode should work the same as without Cluster mode

What do you see instead?

The total received chunks in the worker is different than what I see from client - only in cluster mode, while without it is the same

Additional information

No response

@ywave620
Copy link
Contributor

const cluster = require('node:cluster');
const http = require('node:http');
const process = require('node:process');

process.on('beforeExit', code => {
  console.log(process.pid, 'exited with', code)
})

if (cluster.isPrimary) {
  console.log(`Primary ${process.pid} is running`);

  cluster.fork();
} else {
  // Workers can share any TCP connection
  // In this case it is an HTTP server
  http.createServer((req, res) => {
    console.log(process.pid, 'got request')
    let reqBodyLen = 0
    req.on('data', chunk => {
      reqBodyLen += chunk.length
    })
    req.on('end', () => {
      console.log(reqBodyLen)
      res.writeHead(200);
      res.end('hello world\n');
    })
  }).listen(8082);
  console.log(`Worker ${process.pid} started`);
}

I ran up code adapted from the example in doc, and sent a serval MB request, everything worked well :)
I'm using the latest node.

@MatanYemini
Copy link
Author

Was about to write as well @ywave620 , totally agree...

I suspect it is related to Express in some way. Closing..

@MatanYemini MatanYemini closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2022
@MatanYemini
Copy link
Author

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