Skip to content

core: a concurrent human lease claim can read a partly written lease as stale #298

Closed

Description

@ElbertePlinio

Found in review of PR #289 (#278).

createExclusiveHumanLeaseFile in packages/core/src/takeover.ts creates the lease file with a wx open and writes its content in the same writeFile call, which is two kernel steps. A peer whose own wx open fails can read the file between those steps and get an empty string. parseHumanLease("") returns undefined, so the peer throws StaleHumanLeaseError for a lease that is live and being written. Under Bun the window is microseconds, and the takeover test in PR #289 starts both claims at the same instant.

In the desktop product path, startHumanTakeover runs under withSessionVncLock, so two takeovers of one session do not race there. Other callers of acquireHumanLease have no such lock.

  • Publish the lease by writing a temp file and linking it into place, as publishCoordinationIdentity does, so a peer never sees a partial lease
  • Add a test that a peer never reads a partial lease
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions