Skip to content

socket_helper.transient_internet helper fails when FTP server returns 500 #122999

@freakboy3742

Description

@freakboy3742

Bug report

Bug description:

We've seen a bunch of CI failures over the last few hours in the urllib2 FTP tests. These errors have been observed on iOS (1 2), macOS (1) and Linux (1). [edit: and Windows too (1) – @encukou]

The affected tests are:

  • test_ftp_timeout - test.test_urllib2net.TimeoutTest.test_ftp_timeout
  • test_ftp - test.test_urllib2net.OtherNetworkTests.test_ftp
  • test_ftp_no_timeout - test.test_urllib2net.TimeoutTest.test_ftp_no_timeout
  • test_ftp_basic - test.test_urllib2net.TimeoutTest.test_ftp_basic
  • test_ftp_default_timeout - test.test_urllib2net.TimeoutTest.test_ftp_default_timeout

It's not yet clear how to reliably reproduce the error - it appears to be a transient issue caused by the upstream FTP server raising a 500 error (possibly as a result of #122795).

From a code perspective, the issue is that the error being raised internally is an instance of error_perm; this is used as the err.reason for the URLError raised by urllib2, which breaks the exception filter.

The error manifests as:

Traceback (most recent call last):
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/support/socket_helper.py](http://iostestbed.app/python/lib/python3.13/test/support/socket_helper.py)", line 249, in transient_internet
    yield
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/test_urllib2net.py](http://iostestbed.app/python/lib/python3.13/test/test_urllib2net.py)", line 343, in test_ftp_basic
    u = _urlopen_with_retry(self.FTP_HOST)
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/test_urllib2net.py](http://iostestbed.app/python/lib/python3.13/test/test_urllib2net.py)", line 29, in wrapped
    return _retry_thrice(func, exc, *args, **kwargs)
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/test_urllib2net.py](http://iostestbed.app/python/lib/python3.13/test/test_urllib2net.py)", line 25, in _retry_thrice
    raise last_exc
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/test_urllib2net.py](http://iostestbed.app/python/lib/python3.13/test/test_urllib2net.py)", line 21, in _retry_thrice
    return func(*args, **kwargs)
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/urllib/request.py](http://iostestbed.app/python/lib/python3.13/urllib/request.py)", line 189, in urlopen
    return [opener.open](http://opener.open/)(url, data, timeout)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/urllib/request.py](http://iostestbed.app/python/lib/python3.13/urllib/request.py)", line 489, in open
    response = self._open(req, data)
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/urllib/request.py](http://iostestbed.app/python/lib/python3.13/urllib/request.py)", line 506, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
                              '_open', req)
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/urllib/request.py](http://iostestbed.app/python/lib/python3.13/urllib/request.py)", line 466, in _call_chain
    result = func(*args)
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/urllib/request.py](http://iostestbed.app/python/lib/python3.13/urllib/request.py)", line 1558, in ftp_open
    raise URLError(exp) from exp
urllib.error.URLError: <urlopen error 500 OOPS: vsf_sysutil_bind>


Traceback (most recent call last):
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/test_urllib2net.py](http://iostestbed.app/python/lib/python3.13/test/test_urllib2net.py)", line 349, in test_ftp_default_timeout
    with socket_helper.transient_internet(self.FTP_HOST):
    ...<6 lines>...
        self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/contextlib.py](http://iostestbed.app/python/lib/python3.13/contextlib.py)", line 162, in __exit__
    self.gen.throw(value)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/support/socket_helper.py](http://iostestbed.app/python/lib/python3.13/test/support/socket_helper.py)", line 264, in transient_internet
    filter_error(err)
    ~~~~~~~~~~~~^^^^^
  File "/Users/buildbot/Library/Developer/XCTestDevices/AF99343E-DD9B-4A75-8EE3-3995A510EB7E/data/Containers/Bundle/Application/E807E918-8DD2-4F98-9247-402427533BB4/[iOSTestbed.app/python/lib/python3.13/test/support/socket_helper.py](http://iostestbed.app/python/lib/python3.13/test/support/socket_helper.py)", line 237, in filter_error
    (("ConnectionRefusedError" in err.reason) or
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'error_perm' is not iterable

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions