question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server Crashed after [HPM] Upgrading to WebSocket socket error

See original GitHub issue

Checks

Describe the bug (be clear and concise)

10531652080005_ pic

Step-by-step reproduction instructions

1. Proxy Websocket Broken

Expected behavior (be clear and concise)

Server not crashed, just log errors

How is http-proxy-middleware used in your project?

const { createProxyMiddleware } = require('http-proxy-middleware');

...
createProxyMiddleware({
  target: `http://127.0.0.1:${this.port}/`,
  changeOrigin: true,
  ws: true,
  router: (req) => {
    const url = req.url;
    if (url.startsWith('/xxx')) {
      return null;
    }
    const result = this.router(url, this.url, this.port);
    if (result) {
      return result;
    }
    if (url.startsWith('/v1')) {
      return this.url;
    }
    return `http://127.0.0.1:${this.port}/`;
  },
})
...


### What http-proxy-middleware configuration are you using?

```typescript
{
  target: `http://127.0.0.1:${this.port}/`,
  changeOrigin: true,
  ws: true,
  router: (req) => {
    const url = req.url;
    if (url.startsWith('/xxx')) {
      return null;
    }
    const result = this.router(url, this.url, this.port);
    if (result) {
      return result;
    }
    if (url.startsWith('/v1')) {
      return this.url;
    }
    return `http://127.0.0.1:${this.port}/`;
  },
}


### What OS/version and node/version are you seeing the problem?

```shell
Platform: darwin
Architecture: arm64
Kernal: 21.3.0
Node: v16.14.2
V8: 9.4.146.24-node.20
NPM: 6.14.16
Yarn: 1.22.18

Additional context (optional)

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
whatwewantcommented, May 16, 2022

Hi. Thanks for reporting.

Could you try with http-proxy-middleware@beta? (v3.0.0-beta.0)

V3 registered some additional error handlers to catch the uncaught errors. (https://github.com/chimurai/http-proxy-middleware/blob/master/src/plugins/default/debug-proxy-errors-plugin.ts)

Hopefully it’s already fixed in V3

thanks for reply, i will try it later

0reactions
shekharramolacommented, Nov 8, 2022

It is coming in beta too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle WebSocket error with http-proxy-middleware
The problem I'm having is that if I restart the backend, and the WebSocket connection is interrupted, the whole development server crashes with:...
Read more >
Cryosparc crashes after update to 4.0.0
Hi, I have updated cryosparc as described on the official documentation website. Everything was finished successfully, however, ...
Read more >
WebSocket: error event - Web APIs | MDN
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
Read more >
How to handle a socket hang up error in Node.js usually - Quora
Socket hang up error are usually errors when requests coming to your server are more than it can handle. This might be b...
Read more >
Client Initialization | Socket.IO
If true and if the previous WebSocket connection to the server ... attempt following a transport error will use the normal upgrade process....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found