Skip to content

go: allow concurrent Write calls#621

Merged
djs55 merged 3 commits intomoby:masterfrom
djs55:timeout
Feb 21, 2023
Merged

go: allow concurrent Write calls#621
djs55 merged 3 commits intomoby:masterfrom
djs55:timeout

Conversation

@djs55
Copy link
Copy Markdown
Collaborator

@djs55 djs55 commented Feb 17, 2023

The net.Conn interface says:

// Multiple goroutines may invoke methods on a Conn simultaneously.

Previously concurrent calls to Write() would block for window space but only one would be woken up by a Signal() when a window update is received, allowing the other call to block forever.

The handling of write timeouts was also confusing because

  • time.Sleep couldn't be interrupted
  • the condition variable Wait() was on a temporary goroutine

The code is clearer if each object only acquires its own mutex, and
doesn't reach into the mutexes of others (if possible)

Signed-off-by: David Scott <dave@recoil.org>
Previously we had a complicated set of channels and a condition
variable, and the condition variable Wait() was in a goroutine.

Instead the Wait() is now in the main goroutine and an optional
timeout is in an optional goroutine.

Signed-off-by: David Scott <dave@recoil.org>
If multiple calls are blocked waiting for window space, we need to
use Broadcast() to wake them all up on a window update.

Signed-off-by: David Scott <dave@recoil.org>
@djs55 djs55 merged commit 66d9f18 into moby:master Feb 21, 2023
@djs55 djs55 deleted the timeout branch February 21, 2023 11:07
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