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

Socket hang up #2

Open
boygiandi opened this issue Feb 5, 2020 · 3 comments
Open

Socket hang up #2

boygiandi opened this issue Feb 5, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@boygiandi
Copy link

When I run this proxy, I get this error

Error: socket hang up
at createHangUpError (_http_client.js:330:15)
at Socket.socketOnEnd (_http_client.js:431:23)
at Socket.emit (events.js:202:15)
at Socket.EventEmitter.emit (domain.js:446:20)
at endReadableNT (_stream_readable.js:1129:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)

I tried to fix it and I found this, if I replace the target in original code, from this

  const proxy = httpProxy.createProxy({
    agent: http.globalAgent,
    target: { host, port },
    ws: true
  });

to this

  const proxy = httpProxy.createProxy({
    agent: http.globalAgent,
    target: `http://localhost:${port}`,
    ws: true
  });

It works. I don't really understand why. Maybe you can help me explain it.
I fixed the code in my case, and I also replace the backend to localhost if it's the same with proxy IP.

@endel endel added the enhancement New feature or request label Feb 5, 2020
@MateusMendesSantana
Copy link

Hi. I am having the same problem in an AWS EC2 environment

2020-03-27T14:51:50: PM2 log: Launching in no daemon mode
2020-03-27T14:51:50: PM2 log: [Watch] Start watching smadol
2020-03-27T14:51:50: PM2 log: App [smadol:0] starting in -fork mode-
2020-03-27T14:51:50: PM2 log: App [proxy:1] starting in -fork mode-
2020-03-27T14:51:50: PM2 log: App [smadol:0] online
2020-03-27T14:51:50: PM2 log: App [proxy:1] online
@colyseus/proxy listening at {"address":"::","family":"IPv6","port":8081}
Running on ws://localhost:3000
LISTEN add { processId: 'yOncuSTFq', address: '172.31.26.198:3000' }
Using proxy 0 /matchmake/joinOrCreate/place
PlaceRoom created!
Room is at proxy 0
place closed and saved
Using proxy 0 /matchmake/joinOrCreate/place
PlaceRoom created!
Room is at proxy 0
Using proxy 0 /matchmake/joinOrCreate/place
Room is at proxy 0
Proxy error during: /yOncuSTFq/5d7f7dbb7fa1810ad880b62c?sessionId=Wyrx5AICu
Error: socket hang up
    at connResetException (internal/errors.js:604:14)
    at Socket.socketCloseListener (_http_client.js:400:25)
    at Socket.emit (events.js:323:22)
    at TCP.<anonymous> (net.js:668:12)
place closed and saved
Proxy error during: /yOncuSTFq/5db44ac9d2303724dcebc330?sessionId=YRc1NPxo0
Error: socket hang up
    at connResetException (internal/errors.js:604:14)
    at Socket.socketCloseListener (_http_client.js:400:25)
    at Socket.emit (events.js:323:22)
    at TCP.<anonymous> (net.js:668:12)
Proxy error during: /yOncuSTFq/5db44ac9d2303724dcebc330?sessionId=aEBXNdal6
Error: socket hang up
    at connResetException (internal/errors.js:604:14)
    at Socket.socketCloseListener (_http_client.js:400:25)
    at Socket.emit (events.js:323:22)
    at TCP.<anonymous> (net.js:668:12)

@MateusMendesSantana
Copy link

MateusMendesSantana commented Aug 11, 2020

For production envirioment the HTTP Proxy has no response for OPTIONS requests, so its will give us Cors error.
See it there: http-party/node-http-proxy#872

My temp solution:

const reqHandler = (req: http.IncomingMessage, res: http.ServerResponse) => {
  if (req.method === 'OPTIONS') {
    res.setHeader('access-control-allow-origin', '*');
    res.setHeader('access-control-allow-credentials', 'true');
    res.setHeader('access-control-allow-methods', '*');
    res.setHeader('access-control-allow-headers', '*');
    res.setHeader('access-control-max-age', 60 * 60 * 24 * 30);
    res.statusCode = 200;
    res.end();
    return;
  }
  const proxy = getProxy(req.url!);

  if (proxy) {
    proxy.web(req, res);

  } else {
    console.error('No proxy available!', processIds);
  }
};

After resolve this, i found another problem.
image
the increment_var in ecosystem.config.js does not increment.
now I must pm2 kill then pm2 start every time.
Unitech/pm2#4502

[EDIT]
Another problem. After rerun, the old instance data keep in Redis.
image
So the proxy try to access the old instance, then we will had the ECCONREFUSED error

[EDIT 2]
to clean Redis cache in CI i used:

  • npm install -g redis-cli
  • rdcli -u ${REDIS_URL} flushall

403-Fruit added a commit to 403-Fruit/proxy that referenced this issue May 18, 2021
Implemented CORS support per colyseus#2 (comment)
@zgz682000
Copy link

Hi. I am having the same problem in an AWS EC2 environment

2020-03-27T14:51:50: PM2 log: Launching in no daemon mode
2020-03-27T14:51:50: PM2 log: [Watch] Start watching smadol
2020-03-27T14:51:50: PM2 log: App [smadol:0] starting in -fork mode-
2020-03-27T14:51:50: PM2 log: App [proxy:1] starting in -fork mode-
2020-03-27T14:51:50: PM2 log: App [smadol:0] online
2020-03-27T14:51:50: PM2 log: App [proxy:1] online
@colyseus/proxy listening at {"address":"::","family":"IPv6","port":8081}
Running on ws://localhost:3000
LISTEN add { processId: 'yOncuSTFq', address: '172.31.26.198:3000' }
Using proxy 0 /matchmake/joinOrCreate/place
PlaceRoom created!
Room is at proxy 0
place closed and saved
Using proxy 0 /matchmake/joinOrCreate/place
PlaceRoom created!
Room is at proxy 0
Using proxy 0 /matchmake/joinOrCreate/place
Room is at proxy 0
Proxy error during: /yOncuSTFq/5d7f7dbb7fa1810ad880b62c?sessionId=Wyrx5AICu
Error: socket hang up
    at connResetException (internal/errors.js:604:14)
    at Socket.socketCloseListener (_http_client.js:400:25)
    at Socket.emit (events.js:323:22)
    at TCP.<anonymous> (net.js:668:12)
place closed and saved
Proxy error during: /yOncuSTFq/5db44ac9d2303724dcebc330?sessionId=YRc1NPxo0
Error: socket hang up
    at connResetException (internal/errors.js:604:14)
    at Socket.socketCloseListener (_http_client.js:400:25)
    at Socket.emit (events.js:323:22)
    at TCP.<anonymous> (net.js:668:12)
Proxy error during: /yOncuSTFq/5db44ac9d2303724dcebc330?sessionId=aEBXNdal6
Error: socket hang up
    at connResetException (internal/errors.js:604:14)
    at Socket.socketCloseListener (_http_client.js:400:25)
    at Socket.emit (events.js:323:22)
    at TCP.<anonymous> (net.js:668:12)

I got the same error in my production env. I deploy the @colyseus/proxy service in a docker swarm cluster after a nginx reverse proxy.

@MateusMendesSantana have you solved your problem and do you has the same deployment with me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants