socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
61.3k stars 10.12k forks source link

Getting HTTP error 400 #4881

Open moxpatwa opened 1 year ago

moxpatwa commented 1 year ago

Hello,

I am getting HTTP Error 400 around.

I am using socket-io 4.7.2 and socket-io-client 4.7.2 and I am using react for front end this is my client side settings

Test png

in server side using node is which setting describe below: Test02 png

Can you suggest me solutions for that?

Originally posted by @moxpatwa in https://github.com/socketio/socket.io-client/issues/1474#issuecomment-1828424530

moxpatwa commented 1 year ago

@stouset Any update on above issue

moxpatwa commented 12 months ago

@dshaw and @darrachequesne any update on above issue.

darrachequesne commented 12 months ago

Hi! HTTP 400 status usually means sticky sessions are not enabled properly, could you please check?

Reference: https://socket.io/docs/v4/using-multiple-nodes/

moxpatwa commented 12 months ago

Thanks @darrachequesne .. i will try enable sticky session and let you if i still facing same issue or not.

moxpatwa commented 12 months ago

@darrachequesne I am using node.js for service and react for frontend.. to enable sticky connection can you suggenst me best approach as our nodejs service are contains some rest endpoints ,schedules some job, socketio events. To enable sticky i have made below change in server file

image

and client side code is below:

image

After making these change still getting session is unknown error. let me guide on this.

fillipearaujo commented 12 months ago

For those who are having trouble with sticky session polling on a Kubernetes server. Below is an example of annotations declaration in ingress.yaml to enable the sticky session.

Status: 400 Error: {"code":1,"message":"Session ID unknown"}

   annotations:
     kubernetes.io/ingress.class: nginx
     nginx.ingress.kubernetes.io/affinity: "cookie"
     nginx.ingress.kubernetes.io/session-cookie-name: "route"
     nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
moxpatwa commented 12 months ago

@fillipearaujo Thank for reply but we are creating docker image of nodejs service and deploy and run via aws ec2 instance docker container.

moxpatwa commented 12 months ago

@darrachequesne Any update on issue because it is impact our RTD app. Really appreciate your help on this

moxpatwa commented 11 months ago

@darrachequesne Any update on above issue?

darrachequesne commented 10 months ago

@moxpatwa sticky sessions are needed in case you have multiple Socket.IO server (for example when running with pm2). Is that your case?

See also: https://socket.io/docs/v4/troubleshooting-connection-issues/

moxpatwa commented 10 months ago

@darrachequesne No we dont multiple Socket.io server.

darrachequesne commented 10 months ago

I see you set pingTimeout to 6000 (6 seconds), which might be a bit low on mobile networks. If the client does not respond to the health check in the given delay, then the connection will be closed. Any reason for not using the default value?

Reference: https://socket.io/docs/v4/server-options/#pingtimeout

moxpatwa commented 10 months ago

@darrachequesne Actually i have update code with below

image

But still facing Session ID unknown error

darrachequesne commented 10 months ago

I'm out of ideas then... "Session ID unknown" means the session ID is not recognized by the server, which is usually caused by:

Do you get a "disconnect" event?

socket.on("disconnect", (reason, details) => {
  // the reason of the disconnection, for example "transport error"
  console.log(reason);

  // the low-level reason of the disconnection, for example "xhr post error"
  console.log(details.message);

  // some additional description, for example the status code of the HTTP response
  console.log(details.description);

  // some additional context, for example the XMLHttpRequest object
  console.log(details.context);
});

Reference: https://socket.io/docs/v4/troubleshooting-connection-issues/#problem-the-socket-gets-disconnected

inno-elon commented 5 months ago

I also get this error when using multiple containers in ECS