Skip to content

Pre-mature exit callback or delayed data callbackΒ #3676

@gireeshpunathil

Description

@gireeshpunathil

My bug report below may be inaccurate / irrelevant if I know the background of this test case. Can you please tell me the nomenclature of regression test cases? How do I find out the original problem (GH-1899) for which this test case was developed? #1899 seems to be not related?

The test case test/sequential/test-regress-GH-1899.js implements a simple asynchronous child spawn, which prints a hello world and exits. The parent has a child data callback and exit callback. The essence of the test case is to validate that the child exits gracefully, and the data is indeed received in the parent.

This fails in AIX intermittently with assertion failure:

AssertionError: '' == 'hello, world!\n'
at ChildProcess. (test/sequential/test-regress-GH-1899.js:18:10)

The root cause is that the exit callback is called before the data callback.

I would think that in asynchronous mode, the child's data event and exit event may not receive in the parent in the same order. As both data and exit events arrive as async events in the parent's uv loop, the order can be arbitrary, dictated by the OS based on factors outside the control of node.

If I print the fds appearing in the uv loop, I see that they are not in order always (AIX or Linux):
10 12 14 6
10 14 6 12
Here, fd 6 is for the async child exit event. As you can see, it is not deterministic.

Also, with artificial delay in the code, I am able to make the test fail in Linux.

My point is that while child exit happens chronologically later than the data event in the child, this order may not be maintained in the parent: it can be reversed, or it may trigger together, but depending on the order in which they appear in the resultant array of the epoll call, the execution order can differ, and no program should assume the order as it happen in the child.

Please let me know your views.

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.testIssues and PRs related to the tests.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions