Test isolation: ports are reserved per process, so parallel ctest jobs can be handed the same port

オープン
#1,316 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, python
領域
devtools, testing

調査の方向性

Read tests/apps/isolate.py, especially freePort(), _pickPort() and _portFree(), then trace how the selected port reaches the Apache or broker startup. Check how ctest -j launches the apps_* tests and whether the service can retain a reserved socket. Done means concurrent tests cannot claim the same port and startup failures identify the service and port.

索引モデルが issue の本文から書いたものです。

説明

bug

tests/apps/isolate.py hands out ports with a process-local reservation set, so two
concurrent ctest jobs can be given the same port.

Mechanism. freePort() (tests/apps/isolate.py:154-163) binds a socket to
("127.0.0.1", 0), reads the port the OS offered, closes the socket, and then
only checks the number against _handedOut, a set that lives in the current Python
process:

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.bind(("127.0.0.1", 0))
    port = sock.getsockname()[1]
if port not in _handedOut:
    _handedOut.add(port)
    return port

Between the close and the moment the per-user Apache or the broker actually listens,
the port is unowned. Each apps_* ctest test is its own process with its own empty
_handedOut, so under ctest -j two tests can be offered the same number by the OS
and both proceed. _pickPort() (isolate.py:172-186) probes with _portFree() only
for a port given explicitly in the environment; the port that freePort() returns is
not probed again before the service is started.

Consequence. Not a clean "address already in use". The loser is the service that
starts second: the data server early-exits because something is already listening and
the test then talks to the other test's document root, or the broker fails to come up
and the app under test reports a messaging failure. The log shows an assertion failure
in the application, with no line naming a port, which is exactly the class of false
failure isolate.py's own module docstring (isolate.py:1-12) says it exists to
prevent -- it prevents overlap with a developer's live session, not overlap between
two tests of the same run.

Suggested fix: hold the bound socket open until the service has been handed the port
(bind with SO_REUSEADDR off and pass the fd or close it immediately before exec), or
re-probe with _portFree() and retry when the service fails to bind, and have the
failure message name the port and the service.

Not reproduced: this is read from the code. No run has been traced to a port
collision; under ctest -j the symptom would be an intermittent application-level
failure rather than anything that names a port, so an occurrence would not currently
be recognisable from the log.

主要言語
C
スター
10
フォーク
8
平均マージ
6時間 32分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

FriendsofECCE/ECCE のほかの issue

FriendsofECCE/ECCE の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。