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

TypeError [ERR_INVALID_ARG_TYPE]: The "event" argument must be an instance of Event #73

Closed
andreainnocenti opened this issue Nov 3, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@andreainnocenti
Copy link

It's not uncommon that somebody already opened an issue or in the best case it's already fixed but not merged. That's the reason why you should search at first before submitting a new one.

Please read this entire template before posting any issue. If you ignore these instructions
and post an issue here that does not follow the instructions, your issue might be closed,
locked, and assigned the not reproducible label.

🐛 Bug Report

According to https://nodejs.org/api/events.html#eventtargetdispatcheventevent, the dispatchEvent function must take in input an Event object but in https://github.com/elastic/elastic-transport-js/blob/v8.3.4/src/connection/UndiciConnection.ts#L144, the input is a string.

Currently our microservice crashes if the search reaches the timeout:

 TypeError [ERR_INVALID_ARG_TYPE]: The "event" argument must be an instance of Event. Received type string ('abort')
    at new NodeError (node:internal/errors:405:5)
    at EventTarget.dispatchEvent (node:internal/event_target:687:13)
    at Timeout._onTimeout (/opt/app-root/src/node_modules/@elastic/transport/lib/connection/UndiciConnection.js:128:36)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7) {
  code: 'ERR_INVALID_ARG_TYPE'
}

To Reproduce

Steps to reproduce the behavior:

Expected behavior

Do not crash in case of timeouts.

Your Environment

  • node version: v18
  • @elastic/elasticsearch version: >=8.7.0
  • os: Mac/Linux*
@andreainnocenti
Copy link
Author

andreainnocenti commented Nov 3, 2023

I was able to reproduce the bug also in your unit test.
Screenshot 2023-11-03 at 11 32 43
I only removed this line https://github.com/elastic/elastic-transport-js/blob/main/test/unit/undici-connection.test.ts#L27C1-L27C7.
The package node-abort-controller should not be used in Node.js version >= 16 as described in https://www.npmjs.com/package/node-abort-controller#nodejs-library-only-supports-node-16-or-above.

If you use the native AbortController definition, the app crashes.

@JoshMock
Copy link
Member

JoshMock commented Nov 6, 2023

Good catch @andreainnocenti. I'll pick this up and get it fixed soon.

@JoshMock JoshMock added the bug Something isn't working label Nov 6, 2023
@JoshMock JoshMock self-assigned this Nov 6, 2023
@andreainnocenti
Copy link
Author

Hi @JoshMock, any update on this bug?

@JoshMock
Copy link
Member

I got sidetracked! I'm planning to publish some upgrades in the next few days so I'll try to fit this in.

@JoshMock
Copy link
Member

JoshMock commented Dec 5, 2023

Got a fix for this in #78. I have another PR pending before I planned to push a new version to npm, but if that gets delayed I will try to remember to push a patch version in the next few days.

JoshMock added a commit that referenced this issue Dec 6, 2023
* Dispatch events AbortSignal properly

See #73

* Explicitly drop support for Node.js 14
@JoshMock
Copy link
Member

8.4.0 was published today, including a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants