Skip to content

Fix race condition in collaborative session startup#4803

Merged
stuartc merged 2 commits into
mainfrom
4802-race-condition-on-channel-join
May 29, 2026
Merged

Fix race condition in collaborative session startup#4803
stuartc merged 2 commits into
mainfrom
4802-race-condition-on-channel-join

Conversation

@midigofrank
Copy link
Copy Markdown
Collaborator

@midigofrank midigofrank commented May 27, 2026

Description

Two channel joins for the same workflow could both pass the lookup_shared_doc/1 fast-path and invoke start_document/2 concurrently. The second DynamicSupervisor.start_child returned
{:error, {:already_started, pid}}, which the strict {:ok, _} match did not handle, crashing the channel join.

Treat {:already_started, pid} as success in start_document/2.

Closes #4802

Validation steps

This is hard to replicate manually, I got it on tests though.

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review
    with Claude Code)
  • I have implemented and tested all related authorization policies.
    (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

Two channel joins for the same workflow could both pass the
lookup_shared_doc/1 fast-path and invoke start_document/2 concurrently.
The second DynamicSupervisor.start_child returned
{:error, {:already_started, pid}}, which the strict {:ok, _} match did
not handle, crashing the channel join.

Treat {:already_started, pid} as success in start_document/2.
@github-project-automation github-project-automation Bot moved this to New Issues in Core May 27, 2026
@midigofrank midigofrank requested a review from stuartc May 27, 2026 16:45
@midigofrank midigofrank marked this pull request as ready for review May 27, 2026 16:45
@github-actions
Copy link
Copy Markdown

The PR is a small race-condition fix in collaborative session startup. Changes:

  • lib/lightning/collaboration.ex — handle {:error, {:already_started, pid}} from SessionSupervisor.start_child/1 and return {:ok, pid} for idempotency
  • test/lightning/collaborate_test.exs — new idempotency test
  • CHANGELOG.md — entry

None of S0/S1/S2 are in scope: no project-scoped queries, no new web-layer actions, no config writes.

Security Review ✅

  • S0 (project scoping): N/A — change is internal supervisor child-start logic in Lightning.Collaborate.start_document/2; no new queries or web entrypoints touching project-scoped data.
  • S1 (authorization): N/A — no new controller/LiveView/channel actions; existing channel join authorization is unchanged.
  • S2 (audit trail): N/A — no writes to workflows, credentials, settings, or other config resources.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.3%. Comparing base (6845844) to head (a1c21f3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #4803   +/-   ##
=====================================
  Coverage   90.3%   90.3%           
=====================================
  Files        442     442           
  Lines      22543   22545    +2     
=====================================
+ Hits       20353   20356    +3     
+ Misses      2190    2189    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@midigofrank midigofrank changed the title Fix race in collaborative session startup (#4802) Fix race condition in collaborative session startup May 28, 2026
@stuartc stuartc merged commit 6331486 into main May 29, 2026
1 check was pending
@stuartc stuartc deleted the 4802-race-condition-on-channel-join branch May 29, 2026 10:56
@github-project-automation github-project-automation Bot moved this from New Issues to Done in Core May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Race condition crashes channel join in Collaborate.start_document/2

2 participants