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

Event loop destruction performs file read/write operations in gevent>=20.5.1 #1686

Closed
hashbrowncipher opened this issue Oct 6, 2020 · 2 comments · Fixed by #1728
Closed

Comments

@hashbrowncipher
Copy link
Contributor

  • gevent version: 20.5.1 and later
  • Python version: Python 3.7.7 downloaded using pyenv
  • Operating System: Linux 5.4.0-47-generic, Ubuntu Focal userspace

Description:

The following program reliably hangs on gevent>=20.5.1. It works as expected on gevent 20.5.0.

from gevent.monkey import patch_all
patch_all()  # noqa: E402

import gevent
from gevent.hub import get_hub
from gevent import os
from gevent.monkey import get_original
from gevent.socket import wait_read

hang = get_original("time", "sleep")

r, w = os.pipe()


def pipe_reader():
    os.read(r, 4096)
    print(f"Read from pipe in PID: {os.getpid()}")


print(f"Parent PID: {os.getpid()}")
hub = get_hub()
os.write(w, b"test")
wait_read(r)
gevent.spawn(pipe_reader)
pid = os.fork()
if pid == 0:
    hub.destroy(destroy_loop=True)
else:
    print(f"Child PID: {pid}")
    # Briefly prevent the parent process from executing its event loop
    hang(1)
    os.waitpid(pid, 0)

The expected output looks like this, with a 1 second interval between "Child PID" and "Read from pipe in PID". "Read from pipe in PID" should match "Parent PID":

Parent PID: 2332303
Child PID: 2332306
Read from pipe in PID: 2332303

Unexpected output looks like this, and hangs indefinitely:

Parent PID: 2333255
Child PID: 2333258
Read from pipe in PID: 2333258
@jgehrcke
Copy link
Contributor

jgehrcke commented Oct 8, 2020

This might relate to #1669.

jamadden added a commit that referenced this issue Dec 22, 2020
And stop running callbacks.

This fixes #1686 and fixes #1669.
jamadden added a commit that referenced this issue Dec 22, 2020
And stop running callbacks.

This fixes #1686 and fixes #1669.
@jamadden
Copy link
Member

Thanks for the reports!

I don't have the prerequisites to reproduce #1669, but I do suspect that they are both the same basic issue.

I expect to have this fixed in the next gevent release.

In the meantime and for older versions, if you add hub.loop.break_() just before hub.destroy(destroy_loop=True) I expect it will fix the issue (at least it does this one).

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 a pull request may close this issue.

4 participants
@hashbrowncipher @jgehrcke @jamadden and others