Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type safety wrt locking. #408

Merged
merged 2 commits into from
Dec 29, 2022
Merged

Conversation

zenhack
Copy link
Contributor

@zenhack zenhack commented Dec 29, 2022

This patch introduces a lockedConn type:

type lockedConn Conn

...and moves all methods that require the caller to hold c.lk onto it. It provides methods for running functions while holding the lock.

This makes it much harder to introduce bugs where a method is being called without holding the lock as required, or vice versa.

The patch also fixes a few call sites that were in fact not doing locking correctly, which were caught by the type checker.

The second commit also cleans up some bitrot in the implementation advice comment in rpc.go

This patch introduces a lockedConn type:

```
type lockedConn Conn
```

...and moves all methods that require the caller to hold c.lk onto it.
It provides methods for running functions while holding the lock.

This makes it much harder to introduce bugs where a method is being
called without holding the lock as required, or vice versa.

The patch also fixes a few call sites that were in fact not doing
locking correctly, which were caught by the type checker.
Copy link
Collaborator

@lthibault lthibault left a comment

Choose a reason for hiding this comment

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

LGTM.

The patch also fixes a few call sites that were in fact not doing locking correctly, which were caught by the type checker.

Paying dividends already 😃

@lthibault lthibault merged commit 7eaf071 into capnproto:main Dec 29, 2022
@zenhack zenhack deleted the withLocked branch December 29, 2022 22:21
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