Connecting a socket in timeout mode to a server with full listen backlog raises BlockingIOError
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Verhalten mit den Skripten ms und mc aus dem Issue unter Verwendung eines Unix-Sockets mit listen(0) und wiederholten zeitgesteuerten Verbindungen. Lies die verlinkte Dokumentation zu Socket-Timeouts und Exceptions und untersuche anschließend die relevante CPython-Socket-Implementierung sowie den verlinkten PR gh-134688. Als abgeschlossen gilt die Arbeit, wenn die dokumentierte Timeout-Abstraktion erhalten bleibt, sobald der Listen-Backlog voll ist, und eine Regressionstestabdeckung für den reproduzierten Fall vorhanden ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- networking
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100