nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.92k stars 29.74k forks source link

Hang up with 'advanced' IPC deserialization #55834

Open MGorkov opened 1 week ago

MGorkov commented 1 week ago

Version

20.12.2

Platform

RHEL 8.4

Subsystem

child_process

What steps will reproduce the bug?

I start a child process using fork() and { serialization: 'advanced' }. Then transfer messages between the child and the parent process. Sometimes the transfer hangs at the receiving side.

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

Rarely, after several hours of high rate messaging

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

Transmitting messages without hangups

What do you see instead?

The queue (kMessageBuffer) on the receiving side is constantly growing without processing. The length of the first buffer in the kMessageBuffer is less than 4 bytes, so new messages are not processed and are only added to the end of queue. image

Additional information

I suppose that this PR led to this behavior. Instead of concatenating the queue and then checking the length, only the first buffer is checked. This does not take into account that the first buffer may be smaller than 4 bytes after processing the previous message (code) If the first buffer is less than 4 bytes, it must be concat with with the next one, if there is one.

RedYetiDev commented 1 week ago

Can you provide a minimal reproduction?

MGorkov commented 1 week ago

Minimal reproduction: test-send.zip

node main.js

image

pmarchini commented 1 week ago

Could you please provide a repository or a minimal repro that doesn't require a download?

MGorkov commented 1 week ago

repo for repro