Skip to content

The "fd" argument must be of type number. Received null - Erroring in recent Node versions 20 and 21 #50979

Description

@SamTV12345

Version

v21.2.0

Platform

Linux/MacOS/Windows - same error on all three platforms

Subsystem

No response

What steps will reproduce the bug?

  1. git clone git@github.com:ether/ueberDB.git && git checkout fix/tests
  2. Install Node: Node 20.3.0 works, the respective versions 20 and 21 were released in a time window of 5 days ago
  3. npm i
  4. Run the file test/lib/test.spec.ts
  5. See the tests failing on recent Node versions

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

Always

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

It should run without a problem.

What do you see instead?

TypeError: The "fd" argument must be of type number. Received null

Additional information

No response

Activity

  1. marco-ippolito commented on Nov 30, 2023

    @marco-ippolito
    Member

    Can you share a minimal reproducible example without 3rd party libraries and a stacktrace?

  2. SamTV12345 commented on Nov 30, 2023

    @SamTV12345
    Author

    Sure I'll create one in the next few hours. It was thrown in the dirty db implementation so it shouldn't be too hard to track that down.

  3. SamTV12345 commented on Nov 30, 2023

    @SamTV12345
    Author

    @marco-ippolito Here is the example. I just put it into a test so I can easily start it from webstorm

    import {describe, it} from "vitest";
    import {TMP_PATH} from "./config";
    import fs, {createWriteStream} from "fs";
    
    describe('test-node-failure',  () =>{
    
        it('should allow .on load to chain to constructor', async function () {
            let path = "test.txt"
            let _writeStream = createWriteStream(path, {
                encoding: 'utf-8',
                flags: 'a',
            });
                let _queue = new Map();
                let key = 'key';
    
                const cbs = _queue.get(key) || [];
                _queue.set(key, cbs);
            _writeStream.cork();
            for (const [key, _] of _queue) {
                _queue.delete(key);
                const data = `${JSON.stringify({key, val: "test"})}\n`;
                _writeStream.write(data, (err) => {
                    console.log(err)
                });
            }
            _writeStream.uncork();
            });
    });
  4. SamTV12345 commented on Nov 30, 2023

    @SamTV12345
    Author

    Stacktrace looks like this:

    TypeError: The "fd" argument must be of type number. Received null
        at Object.write (node:fs:834:8)
        at WriteStream.writeAll (node:internal/fs/streams:418:13)
        at WriteStream._write (node:internal/fs/streams:477:12)
        at doWrite (node:internal/streams/writable:590:12)
        at clearBuffer (node:internal/streams/writable:773:7)
        at WriteStream.Writable.uncork (node:internal/streams/writable:523:7)
        at C:\Users\user\WebstormProjects\dirty_db\test\test-minimal.test.ts:25:22
        at file:///C:/Users/user/WebstormProjects/dirty_db/node_modules/@vitest/runner/dist/index.js:135:14
        at file:///C:/Users/user/WebstormProjects/dirty_db/node_modules/@vitest/runner/dist/index.js:58:26
        at runTest (file:///C:/Users/user/WebstormProjects/dirty_db/node_modules/@vitest/runner/dist/index.js:663:17)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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