Skip to content

Bad file descriptor error occurs if random library is imported before closing FDs #67361

Closed

Description

@waynesong
mannequin
BPO 23172
Nosy @vstinner
Superseder
  • bpo-21207: urandom persistent fd - not re-openned after fd close
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2015-01-05.21:27:53.714>
    created_at = <Date 2015-01-05.21:12:41.240>
    labels = ['type-bug', 'library']
    title = 'Bad file descriptor error occurs if random library is imported before closing FDs'
    updated_at = <Date 2015-01-05.21:27:53.712>
    user = 'https://bugs.python.org/waynesong'

    bugs.python.org fields:

    activity = <Date 2015-01-05.21:27:53.712>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-01-05.21:27:53.714>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2015-01-05.21:12:41.240>
    creator = 'waynesong'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 23172
    keywords = []
    message_count = 2.0
    messages = ['233478', '233479']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'waynesong']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '21207'
    type = 'behavior'
    url = 'https://bugs.python.org/issue23172'
    versions = ['Python 3.4']

    Activity

    1. waynesong commented on Jan 5, 2015

      waynesongmannequin
      MannequinAuthor

      The following script:

      import os
      import resource
      import random
      
      print("1")
      
      for fd in range(resource.getrlimit(resource.RLIMIT_NOFILE)[0]):
          try:
              if fd not in range(0, 3):
                  os.close(fd)
          except os.error:
              pass
      
      print("2")
      print(os.urandom(32))
      print("3")

      Crashes with the following output:

      1
      2
      Traceback (most recent call last):
        File "test.py", line 17, in <module>
          print(os.urandom(32))
      OSError: [Errno 9] Bad file descriptor

      On an Ubuntu 14.04 install (in VirtualBox). It seems to run correctly on Mac OS X. The script runs fine if I don't import random at the top.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jan 5, 2015
    3. vstinner commented on Jan 5, 2015

      @vstinner
      Member

      This issue is a duplicate of the issue bpo-21207 which was already fixed in Python 3.4.1.

    4. transferred this issue fromon Apr 10, 2022
    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

      stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions