-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Hard to catch error on proxying in Node.js 10 #1642
Comments
@kmannislands Can you create minimum reproducible test repo? It is hard to fix without this and maybe never will be fixed without this (so issue will be closed) |
@evilebottnawi Minimal repro is more effort here than submitting a PR. I modified my ticket to include the specific code that needs to be changed and how. Not sure what your policy on exception handling/logging is. I'm sure you'll have others trip over this as they go to 10.x |
@kmannislands Fatal error should be don't crash webpack-dev-server so we will accept a PR, but we need test case or minimum reproducible test repo to unsure we fix this problem and avoid regressions in future |
@kmannislands we need minimum reproducible test repo for manual testing (hard to testing), it is increase speed for solving problem |
Can confirm we are also experiencing this error proxying websockets when the server doesn't gracefully respond to the connection or it closes abruptly. Only happens on Node 10.x |
@mjrussell can you create minimum reproducible test repo? |
Friendly ping guys |
Embark API server's development proxy from port 55555 to 3000 was attempting to inappropriately forward an `/embark-api/` endpoint for the blockchain process logs to Create React App's development server. Why it was only happening for the one endpoint is not known but probably has to do with timing around registration of the API server's express routes. The problem can be fixed with a one-line `filter:` function in the options for `express-http-proxy`. However, it was realized that to fix an unrelated problem, whereby the proxy doesn't forward websockets to CRA such that hot reload doesn't work when accessing `embark-ui` in development on port 55555, a switch to `http-proxy-middleware` would be required. That was quickly attempted (easy switch) but there are outstanding [difficulties][bug] with `webpack-dev-server` and `node-http-proxy` that cause CRA to crash. Switch strategies and refactor the API module to serve a page on port 55555 (in development only) that alerts the developer `embark-ui` should be accessed on port 3000. The page redirects (client-side) after 10 seconds, with URL query params and/or hash preserved. A future version could instead do client-side polling of port 3000 with `fetch` and then redirect only once it's available. The reason for not redirecting immediately is that the intermediate page makes it more obvious what needs to be done, e.g. CRA dev server may need to be started with `yarn start`. [bug]: webpack/webpack-dev-server#1642
Embark API server's development proxy from port 55555 to 3000 was attempting to inappropriately forward an `/embark-api/` endpoint for the blockchain process logs to Create React App's development server. Why it was only happening for the one endpoint is not known but probably has to do with timing around registration of the API server's express routes. The problem can be fixed with a one-line `filter:` function in the options for `express-http-proxy`. However, it was realized that to fix an unrelated problem, whereby the proxy doesn't forward websockets to CRA such that hot reload doesn't work when accessing `embark-ui` in development on port 55555, a switch to `http-proxy-middleware` would be required. That was quickly attempted (easy switch) but there are outstanding [difficulties][bug] with `webpack-dev-server` and `node-http-proxy` that cause CRA to crash. Switch strategies and refactor the API module to serve a page on port 55555 (in development only) that alerts the developer `embark-ui` should be accessed on port 3000. The page redirects (client-side) after 10 seconds, with URL query params and/or hash preserved. A future version could instead do client-side polling of port 3000 with `fetch` and then redirect only once it's available. The reason for not redirecting immediately is that the intermediate page makes it more obvious what needs to be done, e.g. CRA dev server may need to be started with `yarn start`. [bug]: webpack/webpack-dev-server#1642
Embark API server's development proxy from port 55555 to 3000 was attempting to inappropriately forward an `/embark-api/` endpoint for the blockchain process logs to Create React App's development server. Why it was only happening for the one endpoint is not known but probably has to do with timing around registration of the API server's express routes. The problem can be fixed with a one-line `filter:` function in the options for `express-http-proxy`. However, it was realized that to fix an unrelated problem, whereby the proxy doesn't forward websockets to CRA such that hot reload doesn't work when accessing `embark-ui` in development on port 55555, a switch to `http-proxy-middleware` would be required. That was quickly attempted (easy switch) but there are outstanding [difficulties][bug] with `webpack-dev-server` and `node-http-proxy` that cause CRA to crash. Switch strategies and refactor the API module to serve a page on port 55555 (in development only) that alerts the developer `embark-ui` should be accessed on port 3000. The page redirects (client-side) after 10 seconds, with URL query params and/or hash preserved. A future version could instead do client-side polling of port 3000 with `fetch` and then redirect only once it's available. The reason for not redirecting immediately is that the intermediate page makes it more obvious what needs to be done, e.g. CRA dev server may need to be started with `yarn start`. [bug]: webpack/webpack-dev-server#1642
Embark API server's development proxy from port 55555 to 3000 was attempting to inappropriately forward an `/embark-api/` endpoint for the blockchain process logs to Create React App's development server. Why it was only happening for the one endpoint is not known but probably has to do with timing around registration of the API server's express routes. The problem can be fixed with a one-line `filter:` function in the options for `express-http-proxy`. However, it was realized that to fix an unrelated problem, whereby the proxy doesn't forward websockets to CRA such that hot reload doesn't work when accessing `embark-ui` in development on port 55555, a switch to `http-proxy-middleware` would be required. That was quickly attempted (easy switch) but there are outstanding [difficulties][bug] with `webpack-dev-server` and `node-http-proxy` that cause CRA to crash. Switch strategies and refactor the API module to serve a page on port 55555 (in development only) that alerts the developer `embark-ui` should be accessed on port 3000. The page redirects (client-side) after 10 seconds, with URL query params and/or hash preserved. A future version could instead do client-side polling of port 3000 with `fetch` and then redirect only once it's available. The reason for not redirecting immediately is that the intermediate page makes it more obvious what needs to be done, e.g. CRA dev server may need to be started with `yarn start`. [bug]: webpack/webpack-dev-server#1642
Embark API server's development proxy from port 55555 to 3000 was attempting to inappropriately forward an `/embark-api/` endpoint for the blockchain process logs to Create React App's development server. Why it was only happening for the one endpoint is not known but probably has to do with timing around registration of the API server's express routes. The problem can be fixed with a one-line `filter:` function in the options for `express-http-proxy`. However, it was realized that to fix an unrelated problem, whereby the proxy doesn't forward websockets to CRA such that hot reload doesn't work when accessing `embark-ui` in development on port 55555, a switch to `http-proxy-middleware` would be required. That was quickly attempted (easy switch) but there are outstanding [difficulties][bug] with `webpack-dev-server` and `node-http-proxy` that cause CRA to crash. Switch strategies and refactor the API module to serve a page on port 55555 (in development only) that alerts the developer `embark-ui` should be accessed on port 3000. The page redirects (client-side) after 10 seconds, with URL query params and/or hash preserved. A future version could instead do client-side polling of port 3000 with `fetch` and then redirect only once it's available. The reason for not redirecting immediately is that the intermediate page makes it more obvious what needs to be done, e.g. CRA dev server may need to be started with `yarn start`. [bug]: webpack/webpack-dev-server#1642
Yes it's still an issue. No I can't produce a minimal repro, concurrency is hard. Please just fix it ❤️ |
@cha0s it is hard to fix something in anything, can you provide screen this about problem? |
@evilebottnawi It seems @kmannislands provided the console output of the error, so pretty much equivalent to a screenshot. Basically, you start the Webpack bundler with proxying, and if any client disconnects it crashes the whole process for the reason mentioned in the original issue, above: Happens on Node v10.x. |
@mathieumg Only Node v10.x? Node.js v12 has been released today so I want to know what occurs using v12. Thanks. |
@hiroppy I presume it will be the same on v12, but I can install it and test it too. Either way, this still needs to be fixed for v10. |
@hiroppy A separate bug prevents me from testing it in v12, but I'm not on the latest version of the Dev Server either:
|
OK, let's talk about this in another issue. |
@mathieumg Could you submit a reproducible repo? |
Yes I can try to muster up a repro repo when I have a spare second sometime this week! |
I tried reproducing this error in a minimal repo, but I can't. Tried with NodeJS 10, 11 and 12. NodeJS 12 doesn't work with WDS though (getting a weird error message different than the one posted above - maybe because I'm on windows). Maybe you guys can use the repo I created. I have definitely seen this behavior in our project using NodeJS 11.x as well: |
IIRC, this also may have depended on a specific chrome version. Perhaps chrome has changed its behavior again. To clarify my original ticket, this is non-blocking because WDS allows users to pass through config to the proxy package. So if anyone reading this is blocked, all you need to do is add an error handler on upgrade to the WDS config in your webpack config: {
// ... other config
devServer: {
proxy: {
'/your_path': {
target: 'https://localhost:XXX',
ws: true,
// Add this:
onError(err) {
console.log('Suppressing WDS proxy upgrade error:', err);
},
},
},
},
} |
hm, i think we should add logger by default as described above, feel free to send a PR, it is easy to fix |
This has just started happening to me but I'm unsure of the change that caused it.
The onError addition above doesn't make a difference I still get the crash with:
It happens at the point I try to open a websocket through the proxy (it doesn't always happen):
|
@markmcdowell can you create minimum reproducible test repo? |
@veloek maybe you can provide full stack trace of the error? |
@alexander-akait This is the error message printed to the console when I recycle the IIS app pool causing WDS to crash:
|
I'm also regularly seeing my webpack-dev-server die until a restart with the same callstack:
my setup looks like this and the error happens whenever the api server is restarted: |
@0x53A Can you provide example to reproduce? What is |
I was on
and updated to
scratch that, just happened again with I'll see if I can create a repro tomorrow. Both the communication from browser to WDS and WDS to api-server is https. Adding
DOES help, then I can see
in the log and WDS continues serving requests. I think the real fix would be nodejs/node#36111. |
@0x53A Anyway, will be great to look there it happens, because it allows us do better checks, will be glad to debug |
I'm not sure about that - I run into this error without any TLS involved (as everything is on localhost):
|
Issue about 3 years, but still patch lives in my sources in postinstall action diff --git a/node_modules/webpack-dev-server/lib/Server.js b/node_modules/webpack-dev-server/lib/Server.js
--- a/node_modules/webpack-dev-server/lib/Server.js
+++ b/node_modules/webpack-dev-server/lib/Server.js
@@ -1840,7 +1840,10 @@ class Server {
(this.server).on(
"upgrade",
/** @type {RequestHandler & { upgrade: NonNullable<RequestHandler["upgrade"]> }} */
- (webSocketProxy).upgrade
+ (req, socket, ...args) => {
+ socket.on('error', (err) => console.error(err));
+ return webSocketProxy.upgrade(req, socket, ...args);
+ }
);
}, this);
}
@alexander-akait Why do we still need this ugly hack? Dev-Server: 4.7.3 |
@Delagen Can you send a PR? Will be great to have test case, I tried to reproduce but no luck |
Hi @alexander-akait. Might have found the issue while working on the next version of http-proxy-middleware. I noticed Added a default handler to Just published http-proxy-middleware@2.0.5 Curious to hear if |
I can confirm this fixes the issue with webpack-dev-server@4.7.4 and http-proxy-middleware@2.0.5 |
@chimurai Thanks for fast fix. It works now. |
Great! I think we can close it, anyway if you faced with this issue - feel free to open an issue, hope we covered all cases |
Glad to hear the fix is working. Thanks @alexander-akait for helping out in this thread. 💪 |
It seems I spoke too soon. I am still getting the error. Somehow the ECONNRESET error is thrown without being caught. I see the error handler in http-proxy-middleware being added, but it does not catch anything. |
@chimurai The The only way I see to catch the error is to add a default |
In http-proxy, there is an error handler on The following in http-proxy-middleware fixes all crashing for me and allows users to still have an proxy.on('econnreset', (err, req, res, target) => {
logger.error(`[HPM] ECONNRESET: %s`, err.message);
});
proxy.on('proxyReqWs', (proxyReq, req, socket, options, head) => {
socket.on('error', (error) => {
logger.error(`[HPM] WebSocket error: %s`, error.message);
});
}); Note that I changed the econnreset handler to log |
Appreciate for your feedback @maknapp! Published Let me know if this fix helps. Bit challenging without a reproduction of the bug 😬 |
@chimurai I can confirm that version 2.0.6 solves the issue. It used to crash for me every time the app pool recycled (IIS), but now it just logs this and keeps running:
So now I can remove the workaround, great work! 🙂 |
v2.0.6 is working for me as well. Thanks @chimurai! |
Is there any way to silent exactly these messages? |
You can setup logging for http-proxy-middleware, there are options for it |
Code
The bug I'm reporting here showed up after switching to Node js v10.x. I believe there are differences in how the
net
core package raises exceptions/policy toward unhandled error events.To repro, you need to proxy a connection that uses WebSockets, allow it to connect using chrome, then restart the target server of the proxy, for example with Nodemon. Want to avoid creating a minimal repo of this if possible since it's a bit comple and there seems to be a nice trail of ticket/changelogs.
This will cause the
WDS
process to die due to unhandled error event fromECONNRESET
with the following stack trace:Before upgrading to node js 10, I believe something similar was happening but the exception wasn't fatal.
After some debugging/ticket searching it seems that what changed is that it is now an error for the https module to encounter an exception without a registered handler, which impacts the behavior of your dependency
node-http-proxy
, like this ticket describes.Debugging the error, I discovered that WDS
proxy
config is reallyhttp-proxy-middleware
config, so it is possible to suppress the error and keep the server up by modifying config by adding an onError handler to proxy config for future readers, however this was fairly difficult to debug and ideally this package would register some sort of handler for this exception so that it isn't fatal.Willing to submit a PR, the change is very straight-forward. Involve modifying this code:
To be like:
Expected Behavior
The server should stay alive when a client (on either side of the proxy) disconnects.
Actual Behavior
Server dies due to no handler for
ECONNRESET
For Bugs; How can we reproduce the behavior?
Use Node 10.
The text was updated successfully, but these errors were encountered: