Connecting a socket in timeout mode to a server with full listen backlog raises BlockingIOError
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
I'm working on a Debian bookworm system. Please consider this executable script ms:
#!/usr/bin/python3 -i
from pathlib import Path
import socket
SOCK = 'stream.sock'
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
Path(SOCK).unlink(missing_ok=True)
s.bind(SOCK)
s.listen(0)
and this one mc:
#!/usr/bin/python3
import socket
SOCK = 'stream.sock'
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.settimeout(3)
s.connect(SOCK)
Let's start ./ms, and once it reaches the Python prompt, run ./mc twice in another terminal:
$ ./mc
$ ./mc
Traceback (most recent call last):
File "/home/wferi/block/./mc", line 8, in <module>
s.connect(SOCK)
BlockingIOError: [Errno 11] Resource temporarily unavailable
The first[^1] invocation runs to completion all right, but all succeeding ones immediately fail with BlockingIOError, as if the connecting socket was in non-blocking mode, not in timeout mode. I understand that the documentation[^2] notes
at the operating system level, sockets in timeout mode are internally set in non-blocking mode
so that must be where this comes from, but such an implementation detail shouldn't leak out of the abstraction, as the documentation also states that
A socket object can be in one of three modes: blocking, non-blocking, or timeout.
and
exception BlockingIOError: Raised when an operation would block on an object (e.g. socket) set for non-blocking operation. [^3]
[^1]: In general the first backlog+1, but I set the listen backlog to 0 in the code of ms above.
[^2]: https://docs.python.org/3/library/socket.html#socket-timeouts
[^3]: https://docs.python.org/3/library/exceptions.html
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
- gh-134688
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with the ms and mc scripts in the issue, using a Unix socket with listen(0) and repeated timed connections. Read the linked socket timeout and exception documentation, then inspect the relevant CPython socket implementation and linked PR gh-134688. Done means the documented timeout abstraction is preserved when the listen backlog is full, with regression coverage for the reproduced case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100