Skip to content

protect source recovery ownership and isolate session tests - #18853

Merged
kevinushey merged 5 commits into
mainfrom
bugfix/18746-source-recovery-safety
Sep 17, 2026
Merged

kevinushey merged 5 commits into
mainfrom
bugfix/18746-source-recovery-safety

Conversation

@kevinushey

@kevinushey kevinushey commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Intent

Improve the source-recovery behavior discussed in #18744 and #18746 with source-database ownership checks, test-launcher isolation, and failure handling for headless script startup. Sessions using different lock types must not mistake each other's live recovery data for abandoned documents.

Approach

  • Check both advisory and link-based ownership before recovering or reusing a source directory. Report an explanatory startup error on contention, including contention encountered during acquisition.
  • Stop --run-script on initialization errors with a nonzero exit status and abnormal cleanup, so scripts cannot continue after source-database ownership checks fail. Log the error and exit directly to avoid Windows modal fatal-error dialogs.
  • Preserve adopted documents when acquiring their lock fails. Continue tolerating explicitly unsupported locking, including advisory probes on filesystems that support only link-based locking; propagate other errors.
  • Retry ambiguous empty lock files until they expire or their ownership becomes clear, with a maximum wait of 30 seconds per directory. This handles recently released advisory locks without treating an unfinished link-lock publication as abandoned.
  • Give each C++ session-test and R-test scope fresh data/config directories on Unix and Windows. Use GUID-based directory names on Windows to avoid repeated cmd random sequences. Create the migration sentinel before startup so legacy user state is not moved into the temporary test directory; stop if setup fails.

Desktop/Server recovery namespaces and persistent-document sharing remain follow-up work in #18746. This change does not establish an atomic ownership-transfer protocol for older binaries. A moved, released symlink lock can still prevent advisory takeover; the documents are preserved and a link-based session can recover them.

Automated Tests

Validated on macOS arm64:

  • Built rsession and rstudio-core-tests.
  • Source-database regression tests: 38 passed, covering mixed lock types, recovery/reuse, acquisition failures, recent advisory release, unsupported advisory probes, and incomplete link publication.
  • Existing file-lock tests: 73 passed, 2 skipped (root-only ACL coverage and a case-sensitive-filesystem test).
  • Shell syntax and git diff --check passed.

Additional ad hoc Windows launcher checks used stub session executables: 4 passed, 1 Unix-only check skipped. These covered inherited state, combined scopes, repeated invocations, and temporary-directory creation failure. GUID-generation failure was also verified to prevent startup in both session scopes. git diff --check passed.

Focused Windows startup regressions passed through rstudio-tests.bat --scope r --filter script-startup: 2 test cases, 9 assertions passed, with no warnings or skips. The success case executes its script; a source-database initialization failure exits with status 1 without executing the script. These tests use isolated child environments and clear inherited POSIX locale settings on Windows.

For this validation, RScriptCallbacks.cpp was rebuilt and relinked against existing local Windows build objects in an isolated directory. This does not validate the complete PR's Windows lock/recovery changes. The new startup tests have not been run on macOS or Linux, and the full unrelated test suite has not been run.

QA Notes

  • With Desktop and Server configured to use different lock types, keep unsaved documents in one session and launch the other. The live session's source directory and contents should remain intact.
  • A second session targeting an owned recovery directory should show a startup error explaining that the recovery data is locked.
  • Run a headless script with source-database initialization blocked. It should log the error, exit with failure, and leave the script unexecuted.
  • Check rapid restart/recovery with advisory locking. A recently created empty lock file may delay startup while its ambiguity expires, up to the limit described above.
  • Run the rsession and r test scopes with inherited data/config settings; each scope should use fresh temporary state and preserve the user's existing state.
  • Verify the Windows launcher in Windows CI or a Windows development environment.

Documentation

Added a NEWS entry linked to #18744.

Checklist

  • Includes a linked NEWS.md entry.
  • Relevant local regression tests pass.
  • A reviewer is assigned.
  • Full Windows lock/recovery runtime verification is complete.

@gtritchie gtritchie added this to the 2026.10 (Blue Mistflower) milestone Sep 16, 2026
@kevinushey
kevinushey deployed to e2e-playwright September 16, 2026 20:55 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 16, 2026 20:55 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 16, 2026 20:56 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 16, 2026 20:56 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 16, 2026 21:00 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 16, 2026 21:00 — with GitHub Actions Active
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
2278 1 127 3
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 4 0
✅ desktop-linux 771 0 38 0
✅ desktop-macos 775 0 33 2
❌ server-linux 714 1 44 1
✅ setup 16 0 8 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 7f85190a95228922edb09da926cbc731a9360d1f - Run #1061

@kevinushey
kevinushey merged commit f82b561 into main Sep 17, 2026
1 of 5 checks passed
@kevinushey
kevinushey deleted the bugfix/18746-source-recovery-safety branch September 17, 2026 03:47
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 04:03 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 04:03 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 04:06 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 04:08 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 04:08 — with GitHub Actions Active
kevinushey added a commit that referenced this pull request Sep 26, 2026
…ease it on failed startup

- Pin the old socket's inode with a hard link in the two identity tests:
  Linux reuses a freed inode number at once, so a rebound socket could
  get the old identity (the Jenkins c++-unit-tests failure).
- Set FD_CLOEXEC on the claimed session socket, so a child that outlives
  a killed session can't make it look alive to the next launch.
- Release the claimed stream (socket + pid file) when rsessionMain returns
  early, i.e. when startup fails after the claim.
- Back out the address_in_use comparison change: server sessions no
  longer reach that retry loop, and enabling it for TCP sessions leaks a
  listener per retry. Left for #18946.
- Drop the NEWS entry: the lockout exists only since #18853 (unreleased).
- Drop bindEndpoint()'s cleanup() call, which is a no-op before a claim.

Addresses #18941.
kevinushey added a commit that referenced this pull request Sep 26, 2026
#18944)

* don't let a duplicate session launch take over a live session's socket

A duplicate rsession launch for the same session unlinked the live
session's stream socket before binding its own, then aborted on the
source-database lock the live session holds (#18853) and removed the
socket it had bound on the way out. The live session was left listening
on an unlinked inode, and every recovery launch repeated the abort, so
the user could not get back in until the original process was killed.

The local stream listener now probes the path before binding and reports
it as in use when a process answers, so the duplicate exits after the
startup retry window instead of supplanting the live session. On exit it
only removes the socket and pid file if they are still the ones it bound
(compared by device and inode), so a supplanted session cannot take its
successor's socket with it either.

rserver could launch the duplicate because a request error landing
between recording a pending launch and learning its pid erased the
entry (the #18572 guard needs a pid); the entry is now kept while the
launch function is in flight. The address_in_use retry comparison in the
session's listener startup never matched asio's system-category error,
and waitWithTimeout now reports the last error that kept it waiting.

Addresses #18941

* claim the session socket first, bind before probing, keep launches through both request outcomes

Fold in the stronger structure from a parallel take on #18941:

- claimSessionStream() binds the session's local stream first thing in
  rsessionMain, before any state a second process for the same session
  would share; a duplicate exits at once with a warning naming the
  owning process. The listener is split into bindEndpoint() and start().
- claimLocalStream() binds without unlinking and probes only on
  EADDRINUSE, so of two processes racing for a missing path the kernel
  picks the winner. stop() runs cleanup() before closing the acceptor,
  so an exiting session unlinks its path while still listening.
- The rserver pending-launch entry is kept through request successes as
  well as errors while the launch function runs, and endLaunching()
  matches on launch time so it never clears a newer entry.
- rstudio-tests gives each run its own RS_SESSION_TMP_DIR: sessions no
  longer take over a socket another test run is listening on.
- Tests adapted and extended (claimLocalStream, bindEndpoint-before-start).

Addresses #18941

* fix socket tests on linux, keep the claimed socket from children, release it on failed startup

- Pin the old socket's inode with a hard link in the two identity tests:
  Linux reuses a freed inode number at once, so a rebound socket could
  get the old identity (the Jenkins c++-unit-tests failure).
- Set FD_CLOEXEC on the claimed session socket, so a child that outlives
  a killed session can't make it look alive to the next launch.
- Release the claimed stream (socket + pid file) when rsessionMain returns
  early, i.e. when startup fails after the claim.
- Back out the address_in_use comparison change: server sessions no
  longer reach that retry loop, and enabling it for TCP sessions leaks a
  listener per retry. Left for #18946.
- Drop the NEWS entry: the lockout exists only since #18853 (unreleased).
- Drop bindEndpoint()'s cleanup() call, which is a no-op before a claim.

Addresses #18941.

This branch was successfully deployed

1 active deployment
e2e-playwright — 7f85190a Deployed Sep 17, 2026 by kevinushey via linux-desktop / E2E (ubuntu-24-x86_64) #1061
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