Skip to content

refactor(lazyClientConn): Use synctest friendly once func#120

Merged
MarcoPolo merged 2 commits intomasterfrom
marco/synctest-friendly-oncefunc
Jun 3, 2025
Merged

refactor(lazyClientConn): Use synctest friendly once func#120
MarcoPolo merged 2 commits intomasterfrom
marco/synctest-friendly-oncefunc

Conversation

@MarcoPolo
Copy link
Contributor

Changes the sync.Once usage to a synctest friendly once version. More context on synctest here: https://go.dev/blog/synctest.

synctest doesn't consider code blocked by a mutex as "durably blocked." This makes sense for the common case where a mutex protects some critical section of code that runs quickly. In multistream's case the protected section of a mutex does IO (it finishes the handshake). This would mean that you would end up deadlocked in a synctest bubble because one goroutine would be waiting to acquire the lock, but the goroutine that would free the lock wouldn't be able to make progress because no network IO or time would happen.

With this change basichost works with synctest.

@MarcoPolo MarcoPolo requested a review from sukunrt April 1, 2025 23:11
@MarcoPolo MarcoPolo force-pushed the marco/synctest-friendly-oncefunc branch from 9577191 to f8b2fec Compare April 2, 2025 00:00
lazyClient.go Outdated
// onceFunc is a sync.Once that can be used by synctest.
// For the Multistream, it is a bit better than sync.Once because it doesn't
// spin when acquiring the lock.
type onceFunc struct {
Copy link
Member

Choose a reason for hiding this comment

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

NIT:

Suggested change
type onceFunc struct {
type once struct {

@MarcoPolo MarcoPolo merged commit 56c815c into master Jun 3, 2025
7 checks passed
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