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

Pathlib throws "Bad file descriptor", but only with uvloop. #414

Closed
decorator-factory opened this issue May 22, 2021 · 9 comments · Fixed by #466
Closed

Pathlib throws "Bad file descriptor", but only with uvloop. #414

decorator-factory opened this issue May 22, 2021 · 9 comments · Fixed by #466

Comments

@decorator-factory
Copy link

decorator-factory commented May 22, 2021

  • uvloop version: 0.15.3
  • Python version: 3.9.5
  • Platform: Manjaro, kernel is 5.10.42-1
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: no
  • Does uvloop behave differently from vanilla asyncio? How?: without uvloop, the script works just fine.

When spawning processes and creating file, an OSError: [Errno 9] Bad file descriptor sometimes appears.

Script and output: https://gist.github.com/decorator-factory/6b5276ab5fb87f4c009f1d22dc4b20a9

Sometimes it also just hangs, with 0 CPU consumption. When I press CTRL+C, I get this traceback: https://gist.github.com/decorator-factory/888a584cbc4d44600ea62f5e7e344b66

Sometimes it completes successfully.

@graingert
Copy link
Contributor

Is this fixed by #408 ?

@decorator-factory
Copy link
Author

Is this fixed by #408 ?

Doesn't seem to be, I just tested on 0.15.3, and I get the same results

@decorator-factory
Copy link
Author

decorator-factory commented Aug 12, 2021

Update: on 16.0 I no longer get the core dump, but the 'bad file descriptor' persists. I wonder if there's something wrong with my system, is there some way to debug the system side of file descriptors?

@th3hamm0r
Copy link

Fyi: I don't know if this is related to that issue, but we see similar log entries of Error while closing socket [Errno 9] Bad file descriptor logged by gunicorn in our django setup with gunicorn, uvicorn, uvloop, websockets, when the server is shutting down. Tested with the latest version of uvloop, uvicorn etc.

@shughes-uk
Copy link

shughes-uk commented May 5, 2022

We are seeing this a lot with asyncio.create_subprocess_exec . Guincorn + uvicorn workers + uvloop+ websockets. Also passing it Path objects and not strings

proc = await asyncio.create_subprocess_exec(
File "/opt/conda/lib/python3.8/asyncio/subprocess.py", line 236, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
File "uvloop/loop.pyx", line 2793, in subprocess_exec
File "uvloop/loop.pyx", line 2751, in __subprocess_run
File "uvloop/handles/process.pyx", line 597, in uvloop.loop.UVProcessTransport.new
File "uvloop/handles/process.pyx", line 127, in uvloop.loop.UVProcess._init
OSError: [Errno 9] Bad file descriptor

graingert added a commit to graingert/uvloop that referenced this issue May 11, 2022
@graingert
Copy link
Contributor

@decorator-factory can you try my patch #466 ?

@shughes-uk
Copy link

shughes-uk commented May 11, 2022 via email

@decorator-factory
Copy link
Author

decorator-factory commented May 18, 2022

@graingert Yes this fixes it for me. Thanks for finding the issue

@cbay
Copy link

cbay commented May 19, 2022

@graingert I can confirm that your one-liner fixes the issue for me as well. I've been running my application for the last few days with your fix, and I haven't had any OSError: [Errno 9] Bad file descriptor since (I had dozens every day before).

Thanks!

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.

5 participants