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.io disconnect after long http request #3376

Closed
karProgrammer opened this issue Nov 22, 2018 · 8 comments
Closed

Socket.io disconnect after long http request #3376

karProgrammer opened this issue Nov 22, 2018 · 8 comments
Labels
question Further information is requested

Comments

@karProgrammer
Copy link

I use socket.io with express server, when I start an http request that take about 20 sec the connection is disconnected then reconnected again. How can I solve this problem?

@johnmanko
Copy link

johnmanko commented Nov 22, 2018

Stackoverflow is a better place to ask support questions: https://stackoverflow.com/questions/tagged/socket.io

@lucid111
Copy link

同样的问题

@johnmanko
Copy link

同样的问题

"same question"

@hequanb
Copy link

hequanb commented Jan 29, 2019

I use nginx to load balance with ip_hash, and the request did goes to the right server with reverse-proxy.
however, some request will fail to get a response from socket.io server, and then they begin to reconnect.
And the error logs of nginx is 'upstream prematurely closed connection while reading response header from upstream',
same question.

@Nishchit14
Copy link

Nishchit14 commented Feb 21, 2019

@karProgrammer Is it still happening?

You can test it in Firecamp, let me know if still facing the issue.

@roy2651
Copy link

roy2651 commented Jul 7, 2020

is this solved?

@darrachequesne
Copy link
Member

@karProgrammer what do you mean by:

when I start an http request that take about 20 sec

Is this a socket.emit()? Or a plain HTTP request to the Express part of your application?

@darrachequesne darrachequesne added the question Further information is requested label Jul 9, 2020
darrachequesne added a commit to socketio/engine.io that referenced this issue Mar 2, 2021
This value was updated from 60000 to 5000 in [1], included in
`[email protected]` (Feb 2018).

The reasoning back then:

Some users experienced long delays between disconnection on the
server-side and on the client-side. The "disconnect" event would take a
long time to fire in the browser, probably due to a timer being
delayed. Hence the change.

That being said, the current value (5s) now causes unexpected
disconnections when a big payload is sent over a slow network, because
it prevents the ping-pong packets from being exchanged between the
client and the server. This can also happen when a synchronous task
blocks the server for more than 5 seconds.

The new value (20s) thus seems like a good balance between quick
disconnection detection and tolerance to various delays.

Note: pingInterval + pingTimeout is still below the threshold of React
Native, which complains if a timer is set with a delay of more than 1
minute.

[1]: 65b1ad1

Related:

- socketio/socket.io#2770
- socketio/socket.io#2769
- socketio/socket.io#3054
- socketio/socket.io#3376
@darrachequesne
Copy link
Member

For future readers: you can increase the value of the pingTimeout option (defaults to 20s now).

I've added a note here: https://socket.io/docs/v4/troubleshooting-connection-issues/#you-are-trying-to-send-a-huge-payload

darrachequesne added a commit to socketio/engine.io that referenced this issue Jun 6, 2022
This value was updated from 60000 to 5000 in [1], included in
`[email protected]` (Feb 2018).

The reasoning back then:

Some users experienced long delays between disconnection on the
server-side and on the client-side. The "disconnect" event would take a
long time to fire in the browser, probably due to a timer being
delayed. Hence the change.

That being said, the current value (5s) now causes unexpected
disconnections when a big payload is sent over a slow network, because
it prevents the ping-pong packets from being exchanged between the
client and the server. This can also happen when a synchronous task
blocks the server for more than 5 seconds.

The new value (20s) thus seems like a good balance between quick
disconnection detection and tolerance to various delays.

Note: pingInterval + pingTimeout is still below the threshold of React
Native, which complains if a timer is set with a delay of more than 1
minute.

[1]: 65b1ad1

Related:

- socketio/socket.io#2770
- socketio/socket.io#2769
- socketio/socket.io#3054
- socketio/socket.io#3376

Backported from 5a7fa13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants