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

Always remove the right listener from the hub #498

Closed

Conversation

smerritt
Copy link
Contributor

@smerritt smerritt commented Jun 8, 2018

When in hubs.trampoline(fd, ...), a greenthread registers itself as a
listener for fd, switches to the hub, and then calls
hub.remove(listener) to deregister itself. hub.remove(listener)
removes the primary listener. If the greenthread awoke because its fd
became ready, then it is the primary listener, and everything is
fine. However, if the greenthread was a secondary listener and awoke
because a Timeout fired then it would remove the primary and promote a
random secondary to primary.

This commit makes hub.remove(listener) check to make sure listener is
the primary, and if it's not, remove the listener from the
secondaries.

I found this when I saw a process running at 100% CPU and strace showed it calling poll() in a tight loop. There was a readable file descriptor, but the process never read it.

@temoto
Copy link
Member

temoto commented Jun 9, 2018 via email

@smerritt
Copy link
Contributor Author

I tried @charmster's suggestion of making that into a .remove(listener), but then some SSL test (tests.ssl_test.SSLTest.test_no_handshake_block_accept_loop) fails because there's a listener that is neither primary nor secondary. I've looked at it, but I don't really understand the SSL stuff enough to understand what's going on.

@codecov-io
Copy link

codecov-io commented Aug 10, 2018

Codecov Report

Merging #498 into master will increase coverage by <1%.
The diff coverage is 76%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #498    +/-   ##
======================================
+ Coverage      45%    46%   +<1%     
======================================
  Files          81     81            
  Lines        7933   8074   +141     
  Branches     1357   1434    +77     
======================================
+ Hits         3595   3730   +135     
+ Misses       4096   4093     -3     
- Partials      242    251     +9
Flag Coverage Δ
#ipv6 ?
#py27epolls 48% <76%> (ø) ⬆️
#py27poll 49% <76%> (+1%) ⬆️
#py27selects ?
#py34epolls 41% <76%> (ø) ⬆️
#py34poll 41% <76%> (ø) ⬆️
#py34selects 40% <76%> (ø) ⬆️
#py35epolls 41% <76%> (ø) ⬆️
#py35poll 42% <76%> (ø) ⬆️
#py35selects 40% <76%> (ø) ⬆️
#py36epolls 41% <76%> (ø) ⬆️
#py36poll 41% <76%> (-1%) ⬇️
#py36selects 40% <76%> (-1%) ⬇️
Impacted Files Coverage Δ
eventlet/hubs/hub.py 90% <76%> (+1%) ⬆️
eventlet/backdoor.py 87% <0%> (-7%) ⬇️
eventlet/hubs/__init__.py 72% <0%> (-6%) ⬇️
eventlet/support/__init__.py 82% <0%> (-5%) ⬇️
eventlet/green/ssl.py 63% <0%> (-2%) ⬇️
eventlet/greenio/base.py 87% <0%> (-1%) ⬇️
eventlet/green/zmq.py 80% <0%> (-1%) ⬇️
eventlet/pools.py 92% <0%> (-1%) ⬇️
eventlet/green/http/client.py 36% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af407c7...a56a722. Read the comment docs.

When in hubs.trampoline(fd, ...), a greenthread registers itself as a
listener for fd, switches to the hub, and then calls
hub.remove(listener) to deregister itself. hub.remove(listener)
removes the primary listener. If the greenthread awoke because its fd
became ready, then it is the primary listener, and everything is
fine. However, if the greenthread was a secondary listener and awoke
because a Timeout fired then it would remove the primary and promote a
random secondary to primary.

This commit makes hub.remove(listener) check to make sure listener is
the primary, and if it's not, remove the listener from the
secondaries.
@clayg clayg mentioned this pull request Sep 23, 2020
@clayg
Copy link
Contributor

clayg commented Sep 23, 2020

I opened #645 if we wanted to move in the direction @charmster suggested - I'm confident this patch fixes a gaping hole for folks using multiple readers as written. IMHO this should merge, and any additional improvements should be follow-ons.

@temoto
Copy link
Member

temoto commented Sep 23, 2020

@smerritt now that core of this patch is merged, please decide whether you want to rebase or close this.

eventlet/hubs/hub.py Show resolved Hide resolved
eventlet/hubs/hub.py Show resolved Hide resolved
eventlet/hubs/hub.py Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #498 into master will increase coverage by 1%.
The diff coverage is 76%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #498     +/-   ##
=======================================
+ Coverage      44%    46%     +1%     
=======================================
  Files          87     81      -6     
  Lines       11831   8074   -3757     
  Branches     1774   1434    -340     
=======================================
- Hits         5254   3730   -1524     
+ Misses       6180   4093   -2087     
+ Partials      397    251    -146     
Flag Coverage Δ
#py27epolls 48% <76%> (-8%) ⬇️
#py27poll 49% <76%> (-7%) ⬇️
#py34epolls 41% <76%> (?)
#py34poll 41% <76%> (?)
#py34selects 40% <76%> (?)
#py35epolls 41% <76%> (-9%) ⬇️
#py35poll 42% <76%> (-8%) ⬇️
#py35selects 40% <76%> (?)
#py36epolls 41% <76%> (-9%) ⬇️
#py36poll 41% <76%> (-9%) ⬇️
#py36selects 40% <76%> (-9%) ⬇️
#py37epolls ?
#py37poll ?
#py37selects ?
#py38epolls ?
#py38poll ?
#py38selects ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
eventlet/hubs/hub.py 90% <76%> (+2%) ⬆️
eventlet/hubs/kqueue.py 0% <0%> (-20%) ⬇️
eventlet/hubs/selects.py 69% <0%> (-2%) ⬇️
eventlet/green/os.py 32% <0%> (-2%) ⬇️
eventlet/backdoor.py 87% <0%> (-1%) ⬇️
eventlet/green/http/cookiejar.py 0% <0%> (-1%) ⬇️
eventlet/zipkin/api.py 0% <0%> (ø)
eventlet/zipkin/wsgi.py 0% <0%> (ø)
eventlet/hubs/pyevent.py 0% <0%> (ø)
eventlet/green/builtin.py 0% <0%> (ø)
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 004cc4e...0443a1f. Read the comment docs.

@smerritt
Copy link
Contributor Author

#645 looks good to me, thanks.

@smerritt smerritt closed this Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants