Connecting a socket in timeout mode to a server with full listen backlog raises BlockingIOError
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue にある ms および mc スクリプトを使い、listen(0) を設定した Unix ソケットと、タイムアウトを設定した接続の反復によって動作を再現します。ソケットのタイムアウトと例外に関するリンク先のドキュメントを読み、その後、関連する CPython のソケット実装と、リンクされている PR gh-134688 を調査します。listen backlog が満杯の場合にも、文書化されている timeout abstraction が維持され、再現したケースに対する回帰テストのカバレッジがあることを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100