Skip to content

Commit

Permalink
avoid loop without yield when sockets are >60 (#138)
Browse files Browse the repository at this point in the history
For Python 2.x, sleep_interval is 0 if len(self.sockets) is above
self.ping_timeout (default: 60). With eventlet, self.sleep(0) looks it
does not yield to the event loop, queueing work which is not processed.
In this condition, the symptom is the server using 100% of CPU after
some time, even when count of sockets drop below self.sockets.

This fix forces sleep_interval to be a float, not equal to 0, forcing
eventlet to yield, processing the queued work and avoiding CPU to be at
100%.

This fix does nothing for Python 3.x.
  • Loading branch information
gawen authored and miguelgrinberg committed Oct 5, 2019
1 parent 51da0be commit 5c6fbea
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def _service_task(self): # pragma: no cover
continue

# go through the entire client list in a ping interval cycle
sleep_interval = self.ping_timeout / len(self.sockets)
sleep_interval = float(self.ping_timeout) / len(self.sockets)

try:
# iterate over the current clients
Expand Down

0 comments on commit 5c6fbea

Please sign in to comment.