Skip to content

use the platform default lock type in desktop mode - #18748

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/18744-linkbased-desktop-locks
Sep 9, 2026
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/18744-linkbased-desktop-locks

Conversation

@kevinushey

@kevinushey kevinushey commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

Intent

Addresses #18744.

RStudio Desktop forced advisory file locks while RStudio Server used link-based locks. The two implementations cannot read each other: a link-based probe sees an advisory lock file (empty, never refreshed) as stale, and an advisory probe sees a link-based lock file (no fcntl holder) as free. When both editions share a data directory, or when a Desktop project lives on a network mount where fcntl fails (#3521), a starting session adopts a live session's source database.

Approach

  • Desktop sessions now call the no-argument FileLock::initialize(), so every mode uses the platform default: advisory on Windows (link-based is not implemented there, and Windows byte-range locks are mandatory and SMB-native), link-based on macOS and Linux. The file-locks configuration file still overrides the type.
  • Updated the comments in the Posit Assistant install lock that described the old desktop/server split.

This finishes what #5668 originally set out to do in 2019; that PR was narrowed during review to keep advisory locks on Desktop. It is complementary to #18745, which makes recovery inspect both lock types (a safety net for customized configs and older binaries), and to the namespace separation proposed in #18746. Note that the isLockedByAnyType comment in #18745 describes the old defaults and can be reworded once both land.

Automated Tests

None added. The change is a default selection; FileLockTests and ChatInstallLockTests exercise both implementations explicitly. SessionMain.cpp was syntax-checked against the existing build's compile flags. A full rebuild and test run were not performed locally.

QA Notes

  • On macOS or Linux, start a Desktop session with no project and confirm ~/.local/share/rstudio/sources/session-<id>/lock_file contains the rsession PID (link-based) rather than being empty (advisory), and that it is touched roughly every 20 seconds.
  • Start a Server-mode session and a Desktop session sharing one RSTUDIO_DATA_HOME, in both orders. Neither session's sources/session-<id> directory should be renamed, and both should still create documents.
  • Kill a Desktop rsession with SIGKILL and relaunch. The orphaned source database should be recovered on the next start.
  • Open a project on an SMB or NFS mount from Desktop, then Session > New Session; the first session should keep saving.
  • Windows behavior is unchanged.
  • On macOS or Linux, open a project on an SMB or NFS mount, stall the mount (e.g. pause the server or block the port) for longer than 30 seconds, then launch a second Desktop session while it is stalled. Until fix file lock correctness #18747 lands, the second session may adopt the first session's source database; this is the known timeout tradeoff of link-based locks, not a regression to fix in this PR.

Documentation

NEWS entry added under Fixed.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards (no UI changes)
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

Desktop sessions forced advisory locks while server sessions used
link-based locks, so two editions sharing a data directory could each
read the other's live session lock as stale and adopt its source
database. Both now take the platform default from FileLock::initialize():
advisory on Windows, link-based on macOS and Linux. The file-locks
configuration file still overrides the choice.

Addresses #18744

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No blocking issues. 1 follow-up, 1 nit.

🟠 is real but not merge-blocking — either address it here or open an issue to do so later. 🟡 is optional.

  • 🟠 src/cpp/session/SessionMain.cpp:2478 — Desktop source-db locks now expire on a 30s timeout
  • 🟡 src/cpp/session/modules/chat/ChatInstallLock.hpp:60 — the file-locks override does not apply on Windows

Verified in passing: Desktop sessions do run the link-based heartbeat (SessionHttpConnectionListenerImpl::start() calls FileLock::refreshPeriodically()), desktopMode is still used further down so nothing goes unused, and the #ifdef _WIN32 branch of FileLock::initialize() keeps Windows on advisory as the description says.

// initialize file lock config. use the platform default (advisory on
// Windows, link-based elsewhere) in every mode: desktop and server
// sessions can share a data directory, and each type misreads the
// other's live locks as stale (#18744)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟠 Link-based locks expire 30s after their last heartbeat write, so a live Desktop session whose refresh is delayed can lose its source database to a starting session.

No change needed to merge — worth an issue to track, or a note in the QA plan to exercise a stalled mount.

Why

The concrete case is the one this PR targets: a project on an SMB/NFS mount. If the mount stalls for more than timeout-interval (30s default), LockRegistration::refreshLocks()'s setLastWriteTime() on sources/session-<id>/lock_file doesn't land. A second Desktop session then hits isLockFileStale(), which ORs the PID check with the mtime check — the PID check passes (the process is alive) but does not veto the mtime verdict — so attachToSourceDatabase() treats the directory as an orphan and sessionDir.move()s it out from under the running session (SessionSourceDatabaseSupervisor.cpp:349-360).

A narrower version of the same window opens on laptop sleep/resume: at wake the lock file's mtime is as old as the sleep, and the refresh timer is boost::asio::system_timer, so it fires promptly — but not before a session launched in that instant can probe.

Advisory fcntl locks had no timeout at all, so this window is new for Desktop. It's the tradeoff the change is making rather than a defect in it; Server has lived with it, and the PR's own QA notes already cover the network-mount path.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed on the mechanism: today the PID check can only confirm staleness, not veto it. #18747 (open) changes inspectLockFile() so that a live local owner stays authoritative even when the heartbeat is delayed, with the mtime timeout used only when the PID cannot be checked (load-balanced). That covers both the stalled-mount and sleep/resume cases for Desktop, so I'd rather track it there than open a separate issue. I've added the stalled-mount scenario to the QA notes here.

// file-locks configuration file.
// same lock type. FileLock::initialize() picks one default per platform
// regardless of desktop/server mode, so sessions sharing a home directory
// agree; the file-locks configuration file can still override it. Mixing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟡 On Windows the file-locks configuration file cannot override the default — lock-type is never read there.

Suggested change
// agree; the file-locks configuration file can still override it. Mixing
// agree; on macOS and Linux the file-locks configuration file can still
// override it (Windows is always advisory). Mixing
Why

FileLock::initialize() sets s_defaultType = LOCKTYPE_ADVISORY unconditionally inside #ifdef _WIN32 (src/cpp/core/file_lock/FileLock.cpp:135-137); the settings.get("lock-type") read only happens in the #else branch. An admin who writes lock-type=linkbased into the system file-locks file on Windows — to match a data directory shared with Linux sessions — gets no change and no warning.

Same caveat applies to the (macOS, Linux) phrasing in ChatInstallLock.cpp:69, though there the runtime check is on the actual lockType value, so only the comment is loose.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, applied your wording in 67d3298.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feedback posted

@kevinushey
kevinushey merged commit e8a6c9a into main Sep 9, 2026
15 checks passed
@kevinushey
kevinushey deleted the bugfix/18744-linkbased-desktop-locks branch September 9, 2026 18:09
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2675 0 193 3
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 674 0 38 1
✅ desktop-macos 672 0 42 0
✅ desktop-windows 678 0 39 2
✅ server-linux 621 0 44 0
✅ setup 28 0 20 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 67d3298447bc6b055d0102f25355caa6f90dd1bb - Run #891

This branch was previously deployed

1 inactive deployment
e2e-playwright — 67d32984 Deployed Sep 9, 2026 by kevinushey via windows / e2e-desktop-windows (5) #891
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