# Hold room lock through the entirety of a \`room_transaction\` · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/8dd249a7cd3f814c54ba0250672ddb37929c4250)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 8dd249a7cd3f814c54ba0250672ddb37929c4250

Requested commit: 8dd249a7cd3f814c54ba0250672ddb37929c4250

Commit: 8dd249a7cd3f814c54ba0250672ddb37929c4250

Tree: bf4fe628056516f4886f85bc24b61059cd373be7

Author: Antonio Scandurra

Committer: Antonio Scandurra

## Message

```
Hold room lock through the entirety of a `room_transaction`

Previously, when the host repeatedly sent `UpdateWorktree` messages,
new guests attempting to join a project would observe a severe slowdown
caused by a database serialization error (e.g., the coherence of the data
would get violated midway through `Database::join_project` due to worktree
entries being mutated as the user joined). Writing entries is pretty fast,
whereas reading all of them for a project can take more than 100ms.
Transactions that failed due to a serialization error are retried, but the guest
would keep retrying until the host finished writing because the guest's read
was slow.

This commit changes the semantics of `room_transaction` to acquire a room
lock before even starting the transaction and holding it all the way after
commit (storing it, as before, in the `RoomGuard`). This ensures that a fast
writer (the host) can't starve a slow reader (the guest), allowing the latter
to make progress by temporarily pausing writes by the former.

```

## Parents

- [24fcad3fa2ce9762ee676f80acf89b53a28bf539](https://git.cafe/gitcafe/zed/commit/24fcad3fa2ce9762ee676f80acf89b53a28bf539?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/8dd249a7cd3f814c54ba0250672ddb37929c4250?format=markdown)
