Skip to content

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

Description

@decorator-factory
  • 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.

Activity

  1. graingert commented on Jul 13, 2021

    @graingert
    Contributor

    Is this fixed by #408 ?

  2. decorator-factory commented on Jul 13, 2021

    @decorator-factory
    Author

    Is this fixed by #408 ?

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

  3. decorator-factory commented on Aug 12, 2021

    @decorator-factory
    Author

    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?

  4. th3hamm0r commented on Sep 29, 2021

    @th3hamm0r

    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.

  5. shughes-uk commented on May 5, 2022

    @shughes-uk

    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
    
  6. added a commit that references this issue on May 11, 2022
    80f3e40
  7. graingert commented on May 11, 2022

    @graingert
    Contributor

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

  8. shughes-uk commented on May 11, 2022

    @shughes-uk
  9. decorator-factory commented on May 18, 2022

    @decorator-factory
    Author

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

  10. cbay commented on May 19, 2022

    @cbay

    @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!

  11. added a commit that references this issue on Jul 16, 2022
    b6d0e79
  12. added a commit that references this issue on Jul 17, 2022
    72140d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions