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

NODE_V8_COVERAGE leads to different behavior, dispatcher.on is not a function #2328

Closed
loynoir opened this issue Oct 10, 2023 · 3 comments · Fixed by #2330
Closed

NODE_V8_COVERAGE leads to different behavior, dispatcher.on is not a function #2328

loynoir opened this issue Oct 10, 2023 · 3 comments · Fixed by #2330

Comments

@loynoir
Copy link

loynoir commented Oct 10, 2023

Version

v20.8.0

Platform

Docker ArchLinux 6.1.55-1-lts

Subsystem

No response

What steps will reproduce the bug?

$ cat reproduce.mjs 
import { fetch as $fetch, Agent } from "undici";

const controller = new AbortController();

await $fetch("http://127.0.0.1:1234", {
  signal: controller.signal,
});
$ 
$ node reproduce.mjs 
$ 
$ env NODE_V8_COVERAGE='./coverage/tmp' node ./reproduce.mjs
/tmp/tmp.UqQMFN5Qmf/node_modules/undici/index.js:110
        Error.captureStackTrace(err, this)
              ^

TypeError: dispatcher.on is not a function
    at fetch (/tmp/tmp.UqQMFN5Qmf/node_modules/undici/index.js:110:15)
    at async file:///tmp/tmp.UqQMFN5Qmf/reproduce.mjs:5:1

Node.js v20.8.0

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

No response

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

NODE_V8_COVERAGE does not leads to different behavior.

$ node reproduce.mjs 
$ 
$ env NODE_V8_COVERAGE='./coverage/tmp' node ./reproduce.mjs
$

What do you see instead?

NODE_V8_COVERAGE leads to different behavior.

$ node reproduce.mjs 
$ 
$ env NODE_V8_COVERAGE='./coverage/tmp' node ./reproduce.mjs
/tmp/tmp.UqQMFN5Qmf/node_modules/undici/index.js:110
        Error.captureStackTrace(err, this)
              ^

TypeError: dispatcher.on is not a function
    at fetch (/tmp/tmp.UqQMFN5Qmf/node_modules/undici/index.js:110:15)
    at async file:///tmp/tmp.UqQMFN5Qmf/reproduce.mjs:5:1

Node.js v20.8.0

Additional information

No response

@loynoir loynoir changed the title NODE_V8_COVERAGE leads to different behavior NODE_V8_COVERAGE leads to different behavior, dispatcher.on is not a function Oct 10, 2023
@KhafraDev KhafraDev transferred this issue from nodejs/node Oct 11, 2023
@loynoir
Copy link
Author

loynoir commented Oct 11, 2023

I created issue in nodejs/node https://github.com/nodejs/node/issues/50129.

I don't know why this issue transfer from nodejs/node to nodejs/undici


Quote @KhafraDev

FinalizationRegister gets disabled with coverage -> use undici's compat one -> attempt to use .on with an AbortController -> error. idk what the expected behavior here is.


FinalizationRegister gets disabled with coverage

@KhafraDev @mcollina


use undici's compat one

  • What is a undici's compat one?

  • Is there a way not to use compat one?


attempt to use .on with an AbortController -> error

  • Is there a manually cleanup way, undici.addSignal, undici.removeSignal?
    const SUGGESTION_A = "undici.addSignal(signal)";
    const SUGGESTION_B = "undici.removeSignal(signal)";

    if (dispatcher.on) {
      dispatcher.on("disconnect", () => {
        this.finalizer(key);
        if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) {
        }
        this.finalizer(key);
      });
    } else {
      // https://github.com/nodejs/node/issues/49344
      if (registedSignal.get(signal)) {
        console.debug(`should call ${SUGGESTION_B} after fetch`)
      } else {
        throw new Error(
          `should call ${SUGGESTION_A} before fetch, and call ${SUGGESTION_B} after fetch`
        );
      }
    }

@meyfa
Copy link
Contributor

meyfa commented Oct 11, 2023

Right, it seems to me that this issue was caused by #2298, which is a workaround for a bug in Node.js. Maybe it's not such a good idea to fix this issue, which was introduced by a workaround, with yet another workaround. I don't have time to come up with a reproduction, but it feels like #2330 would probably break stuff in unexpected ways. These failures will be hard to track down as well, since they depend on the execution environment, and not only the code. Please do not branch the execution based on whether coverage is enabled or not.

@loynoir

I don't know why this issue transfer from nodejs/node to nodejs/undici

Well, you are importing from the undici package in your reproduction. This is the repository for that.

@loynoir
Copy link
Author

loynoir commented Oct 11, 2023

@meyfa

Thanks for the link.

Now, I understand the situation.

  • undici already workaround node bug.

  • but that workaround not cover controller.signal.

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

Successfully merging a pull request may close this issue.

2 participants