Skip to content

Recursively calling makepasv() finally leads to core dumped. #90369

Closed as not planned

Description

@xxm
mannequin
BPO 46211

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 = None
created_at = <Date 2021-12-31.05:45:05.680>
labels = ['3.10', 'library', '3.9', 'type-crash', '3.11']
title = 'Recursively calling makepasv() finally leads to core dumped.'
updated_at = <Date 2021-12-31.05:45:05.680>
user = 'https://bugs.python.org/xxm'

bugs.python.org fields:

activity = <Date 2021-12-31.05:45:05.680>
actor = 'xxm'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-12-31.05:45:05.680>
creator = 'xxm'
dependencies = []
files = []
hgrepos = []
issue_num = 46211
keywords = []
message_count = 1.0
messages = ['409408']
nosy_count = 1.0
nosy_names = ['xxm']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue46211'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Linked PRs

Activity

  1. xxm commented on Dec 31, 2021

    xxmmannequin
    MannequinAuthor

    See the following 'test.py', we call client.makepasv() in socket, and then create_connection. Recursively calling makepasv() finally leads to core dumped.

    System: Python 3.10.1, 3.11.0a3 ,master on Ubuntu 18.04

    Reproduce step:

    1. executing "python test.py"
    2. If only TimeoutError is observed, just executing this code again. Maybe after 4 or 5 times, this program crashes Python interpreter.

    test.py
    ===============================================

    import socket
    from test.test_ftplib import TestFTPClass,TIMEOUT
    
    def test_makepasv():
        host, port = TestFTPClass.client.makepasv()
        conn = socket.create_connection((test_makepasv(), host), timeout=TIMEOUT)
        conn.close()

    ===============================================

    Error Message:
    ---------------------------------------------------

    Exception in thread Thread-1:
    Traceback (most recent call last):
      File "/home/xxm/Desktop/compilers/cpython-main12-31/Lib/asyncore.py", line 90, in read
        obj.handle_read_event()
        ^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/xxm/Desktop/compilers/cpython-main12-31/Lib/asyncore.py", line 427, in handle_read_event
    Traceback (most recent call last):
    .....
      File "/home/xxm/Desktop/compilers/cpython-main12-31/Lib/test/test_ftplib.py", line 298, in run
        return self._sock.recv_into(b)
               ^^^^^^^^^^^^^^^^^^^^^^^
    TimeoutError: timed out
    Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stderr>'> at interpreter shutdown, possibly due to daemon threads
    Python runtime state: finalizing (tstate=0x0000556df3cfbe30)

    Current thread 0x00007fb82ce69080 (most recent call first):
    <no Python frame>

    Extension modules: _testcapi (total: 1)
    Aborted (core dumped)
    -----------------------------------------------------

  2. added
    3.11only security fixes
    stdlibStandard Library Python modules in the Lib/ directory
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Dec 31, 2021
  3. transferred this issue fromon Apr 10, 2022
  4. duaneg commented on Jun 16, 2025

    @duaneg
    Contributor

    The reproduction no longer works on current HEAD. However, it is recursively opening FTP connections until it either runs out of FDs or the stack overflows. The crash is coming from a daemon thread started by the test code, which is inherently racy with shutdown.

    Since test framework is only meant for internal use and it isn't being used correctly, I'd normally suggest just closing this. However, IIUC, we do want to eliminate daemon threads and their raciness where we can (right @ZeroIntensity?).

    As it turns out the threads were originally joinable and were daemonized in 529525f for #7079, but the code that joined them was left intact. The commit message doesn't mention the change and it looks like it was perhaps a mistake. @tiran, do you recall anything about it?

    There was another thread in test_poplib which was daemonized in the same commit and which can also be made joinable safely.

  5. added a commit that references this issue on Jun 16, 2025
  6. ZeroIntensity commented on Jun 16, 2025

    @ZeroIntensity
    Member

    However, IIUC, we do want to eliminate daemon threads and their raciness where we can (right @ZeroIntensity?).

    I personally don't like daemon threads, but they're not necessarily an issue themself. See this section in PEP 788. Ideally, we'll solve the raciness in C code via interpreter references, not by removing usage of daemon threads from Python code.

  7. ZeroIntensity commented on Jun 23, 2025

    @ZeroIntensity
    Member

    Closing per discussion in GH-135560

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

    3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions