Skip to content

Avoid python-iptables stdout race in partition tests - #8292

Open
Amaury Chamayou (achamayou) wants to merge 3 commits into
mainfrom
achamayou-fix-partition-iptables-race
Open

Avoid python-iptables stdout race in partition tests#8292
Amaury Chamayou (achamayou) wants to merge 3 commits into
mainfrom
achamayou-fix-partition-iptables-race

Conversation

@achamayou

@achamayou Amaury Chamayou (achamayou) commented Sep 4, 2026

Copy link
Copy Markdown
Member

Summary

  • replace in-process python-iptables calls with iptables --wait subprocesses
  • rely on private per-Partitioner chains and the xtables cross-process lock instead of a redundant process-local lock
  • remove the now-unused python-iptables dependency

Context

After #8254 made partition groups concurrent, #8249's CI failed with ValueError: No closing quotation. python-iptables temporarily replaces process-wide stdout while serialising a rule; a concurrent {in-place-restart} Loguru line entered that captured buffer and broke shlex.split.

Running the CLI in a subprocess isolates its output from all parent test threads rather than relying on every stdout writer to coordinate with the iptables operation. --wait takes the exclusive xtables lock for each update, and concurrent sub-tests operate on distinct chains.

Testing

  • exercised four private chains concurrently through create/check/insert/delete/cleanup while another thread continuously wrote unmatched quotes to stdout
  • Black and Ruff
  • copyright and ASCII checks

Run partition firewall operations through the iptables CLI so its output is isolated from concurrent test logging. Use --wait for cross-process updates and remove the unused Python binding.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6e6066b0-464e-4b74-9d4e-29953fa3de77
Copilot AI lite review requested due to automatic review settings September 4, 2026 19:38
@achamayou
Amaury Chamayou (achamayou) requested a review from a team as a code owner September 4, 2026 19:38
Each Partitioner owns a private chain, while iptables --wait serializes individual table updates across every process. No worker threads share a Partitioner, so the old process-local lock no longer protects shared state.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6e6066b0-464e-4b74-9d4e-29953fa3de77

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The migration to iptables subprocess calls is consistent throughout the partitioning helper, and no remaining python-iptables/iptc usage was found in the repository.

Pull request overview

This PR updates the e2e partition test infrastructure to avoid python-iptables’ process-wide stdout capture race by switching to iptables --wait subprocess calls, and removes the now-unused python-iptables dependency from the test requirements.

Changes:

  • Replaced in-process python-iptables usage with iptables CLI subprocess helpers (with --wait) to avoid stdout corruption under concurrent logging.
  • Kept per-process atomicity of related rule updates via a re-entrant lock while relying on xtables locking to serialize individual iptables operations across concurrent ctest processes.
  • Removed python-iptables from tests/requirements.txt.

Custom instructions used: None (no .github/copilot-instructions.md / .github/instructions/* files were explicitly loaded during this review).

File summaries
File Description
tests/requirements.txt Drops python-iptables dependency now that tests invoke iptables via subprocess.
tests/infra/partitions.py Reworks partition rule manipulation to call iptables --wait in subprocesses and removes iptc/JSON-based dumping.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Remove unused dataclass fields from the non-dataclass Rules type, fix its fallback label, and make unsupported-field diagnostics deterministic.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6e6066b0-464e-4b74-9d4e-29953fa3de77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants