Skip to content

fix: keep relay tests from flooding the host and racing the relay - #153

Merged
avifenesh merged 3 commits into
mainfrom
fix/relay-holder-registration
Oct 25, 2026
Merged

avifenesh merged 3 commits into
mainfrom
fix/relay-holder-registration

Conversation

@avifenesh

@avifenesh avifenesh commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Found while cutting 0.5.0 (#152 CI failed on a relay test).

  • closes_clients_that_queue_descriptors_without_messages queued about 1,000 descriptors in flight. In-flight SCM_RIGHTS descriptors are a per-user budget (ETOOMANYREFS past the sender's RLIMIT_NOFILE) shared with the desktop session: a looped local run made kitty's Wayland connection fail and kitty exited. The per-connection cap is now a Limits field (production value unchanged, 1024) and the tests use 56, so no test keeps more than about 100 descriptors in flight.
  • The shared-budget case raced the relay reading the first connection's descriptors; it now waits on SIOCOUTQ until they are read.
  • Relay holders connect upstream only after the daemon records their pid mapping (a go byte on the control socket), so a compositor never sees an unmapped holder. This was the chore: release v0.5.0 #152 CI failure.
  • closed() treats ECONNRESET as closed.

Validation: fmt, clippy -D warnings, 254 tests (default and symlinked TMPDIR), 40 consecutive relay-test runs without a failure.


Note

Medium Risk
Production relay path changes holder startup synchronization (pid mapping before upstream connect); limits are unchanged but fork/control-socket behavior is security-relevant for window pid attribution.

Overview
Fixes relay correctness and test hygiene in the sandbox Wayland filter.

Holder connect ordering: The parent now inserts the holder→client pid mapping in PEERS before the holder connects upstream, signaled by a one-byte “go” on the control socket. The holder blocks on that byte so the compositor never sees a connection without a mapping (addressing CI failures from #152).

Descriptor budgets: Limits gains per_connection_fds (still 1024 in production via from_rlimit). Budget is created once per accept loop and carries connection and per-connection caps; pump enforces the per-connection limit through budget.per_connection instead of a hardcoded constant.

Tests: Descriptor-flood cases use caps of ~56 in flight instead of ~1000, avoiding shared per-user SCM_RIGHTS limits that could break the desktop session. The shared-budget scenario uses Harness::wait_queued so the relay has counted the first connection’s fds before the second connects. closed() treats ECONNRESET as a closed socket.

Reviewed by Cursor Bugbot for commit fb5213d. Configure here.

- The flood test queued about 1,000 descriptors in flight over Unix
  sockets. In-flight descriptors are a per-user budget shared with the
  desktop; a looped run made kitty's Wayland connection fail with
  ETOOMANYREFS and close every session in it. The per-connection cap is
  now a Limits field, and the tests use caps of 56.
- The shared-budget case assumed the relay had counted the first
  connection's descriptors; it now waits until they are read.
- Relay holders connect upstream only after their pid mapping is
  recorded, so a compositor never sees an unmapped holder.
- A connection reset counts as closed in the test helper.
Copilot AI balanced review requested due to automatic review settings October 25, 2026 12:06
@cursor

cursor Bot commented Oct 25, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 3080cb7d-1c09-4a8c-97fe-5f26b17dd506)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is an auto review done by revuto.


The holder handshake and production limits look consistent, but the shared-budget test still has a synchronization race.

Comment thread src/session/wayland_filter.rs Outdated
Retry the go-byte read on EINTR, send it with MSG_NOSIGNAL, refuse to
proceed when the pid map is poisoned, and make the flood test assert the
relay does not close before the cap.
@avifenesh

Copy link
Copy Markdown
Collaborator Author

Self-review (independent fresh-context reviewer): nothing serious. Production behavior unchanged except the holder handshake, which is async-signal-safe, cannot deadlock or leak the holder, and is bounded by the existing 5 s receive timeout. Its P3 notes are applied in the head commit (EINTR retry, MSG_NOSIGNAL, poisoned pid map refuses, a real assertion in the flood test); the SIOCOUTQ-to-count gap is documented as far shorter than the next connect. Validation: fmt, clippy -D warnings, 254 tests in both TMPDIR modes, 40 consecutive relay-test runs.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 14:56
@cursor

cursor Bot commented Oct 25, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: ddf7d04e-749e-4dea-a48c-b7d29f026dc1)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is an auto review done by revuto.


The shared-budget test still has the previously reported race; the new timing assumption does not synchronize the relay threads.

Comment thread src/session/wayland_filter.rs Outdated
SIOCOUTQ reaches zero before the pump adds the descriptors to the shared
budget, so the second connection could still be counted first. The
budget is now built outside accept_loop and the test harness waits on
its counter.
Copilot AI balanced review requested due to automatic review settings October 25, 2026 15:15
@cursor

cursor Bot commented Oct 25, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: 0e4fa240-e94d-4ee8-917b-5a531a8eecf9)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is an auto review done by revuto.


Revuto completed the review and found no evidence-backed concerns.

@avifenesh
avifenesh merged commit 7695922 into main Oct 25, 2026
10 checks passed
@avifenesh
avifenesh deleted the fix/relay-holder-registration branch October 25, 2026 19:21
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