-
Notifications
You must be signed in to change notification settings - Fork 102
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
Terminal Intercepting crashes when using NodeJS worker threads #91
Comments
Technically, we're setting both, here:
That said, it totally makes sense to me that Windows collapses these into a single variable when it ignores case, and then that Node bug (thanks for filing that!) makes it case sensitive to the selected result. I don't want to overcomplicate this (e.g. to handle all possible casings) since in theory the current approach is 'correct' (set both vars, read one of them, expect that to be set) and it seems there's a proper fix en route for the specific node bug anyway. For now, I've just added the simplest fix, which should resolve this for your specific Undici issue and also various other cases (e.g. global-agent reads HTTP_PROXY internally I think, which is presumably broken as well, though not actually crashing). I've pushed that here: 0a3d0af. Can you give that a quick test and confirm it works for you? |
Yup, that patch fixes the issue for me! |
Sadly it seems that the NodeJS team has decided to add this behavior to the docs instead of fixing it. |
HTTP Toolkit Terminal Interceptor currently crashes when executing a script that uses Worker threads
Exception
The error originates here:
httptoolkit-server/overrides/js/prepend-node.js
Lines 61 to 71 in 89ba2ec
After some investigation, it turns out that you are setting the envoirement variable
http_proxy
, but in code attempt to access it asHTTP_PROXY
. In a regular NodeJS context, this works fine since theprocess.env
object does some getter magic to make property accessing case-insensitive. This is correct and expected, as envoirement variables on windows are intended to be case-insensitive.Documented here:
On Windows operating systems, environment variables are case-insensitive.
In worker threads, however, this behavior does not apply, and
process.env.HTTP_PROXY
returnsundefined
when the variable is calledhttp_proxy
, which causes the ProxyAgent to get called without an uri, causing the crash as seen above.On new node versions this happens even without importing undici within the worker, since HTTP Toolkit automatically imports undici to proxy the global
fetch
object.httptoolkit-server/overrides/js/prepend-node.js
Lines 117 to 124 in 89ba2ec
The worker threads documentation doesn't explicitly state wether
process.env
in workers should be case-sensitive or -insensitive, but it seems reasonable to assume that this detail was simply forgotten.I'm thus going to create an issue in the NodeJS repo as well, however HTTP Toolkit should still implement a workaround for this (perhaps trying to get both the fully-uppercase and the fully-lowercase variant, or getting the keys of
process.env
and finding the one that case-insensitively matches the env var name to even find variables that are matched inconsistently, e.g.Http-Proxy
)Here's a repro of the issue:
Reproduction code
logs:
TLDR: process.env isn't case insensitive in NodeJS Worker Threads, which breaks the Terminal Interceptor. Make the terminal interceptor manually search for the "http_toolkit" variable in different casings as a workaround.
The text was updated successfully, but these errors were encountered: