Repository navigation
use the platform default lock type in desktop mode - #18748
Conversation
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
left a comment
There was a problem hiding this comment.
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— thefile-locksoverride 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) |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
🟡 On Windows the file-locks configuration file cannot override the default — lock-type is never read there.
| // 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.
There was a problem hiding this comment.
Good catch, applied your wording in 67d3298.
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
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
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. Thefile-locksconfiguration file still overrides the type.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
isLockedByAnyTypecomment in #18745 describes the old defaults and can be reworded once both land.Automated Tests
None added. The change is a default selection;
FileLockTestsandChatInstallLockTestsexercise both implementations explicitly.SessionMain.cppwas syntax-checked against the existing build's compile flags. A full rebuild and test run were not performed locally.QA Notes
~/.local/share/rstudio/sources/session-<id>/lock_filecontains the rsession PID (link-based) rather than being empty (advisory), and that it is touched roughly every 20 seconds.RSTUDIO_DATA_HOME, in both orders. Neither session'ssources/session-<id>directory should be renamed, and both should still create documents.Documentation
NEWS entry added under Fixed.
Checklist
NEWS.md