Skip to content

Conversation

maxatome
Copy link
Contributor

@maxatome maxatome commented Sep 30, 2022

If Connection.async is not initialized before calling binder.Bind()
and a goroutine is spawned in binder.Bind() to monitor the end of the
connection using conn.Wait(), this conn.Wait() can wait forever:

func (s *MyServer) Bind( ctx context.Context, conn *jsonrpc2.Connection, ) (jsonrpc2.ConnectionOptions, error) { // XXX register conn in *MyServer // monitor the end of the connection go func() { conn.Wait() conn.Close() // YYY do some cleanup in *MyServer }() return jsonrpc2.ConnectionOptions{}, nil } 

The "// YYY do some cleanup in *MyServer" should be reached for each
end of connection.

If Connection.async is initialized too late, after conn.Wait() is
called in the Bind() spawned goroutine, conn.Wait() never returns as
it reads on a nil conn.async.ready channel.

Fixes #56131.

@gopherbot
Copy link
Contributor

This PR (HEAD: 0ef160d) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/exp/+/436888 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@maxatome
Copy link
Contributor Author

@gopherbot
Copy link
Contributor

Message from Bryan Mills:

Patch Set 1:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@ianlancetaylor
Copy link
Contributor

The "Fixes" comment needs to go into the initial comment describing this pull request, so that it gets copied into Gerritt. See https://go.dev/wiki/Gerritbot. Thanks.

@gopherbot
Copy link
Contributor

This PR (HEAD: 477196f) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/exp/+/436888 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 2:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 9067b31) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/exp/+/436888 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

If Connection.async is not initialized before calling binder.Bind() and a goroutine is spawned in binder.Bind() to monitor the end of the connection using conn.Wait(), this conn.Wait() can wait forever: func (s *MyServer) Bind( ctx context.Context, conn *jsonrpc2.Connection, ) (jsonrpc2.ConnectionOptions, error) { // XXX register conn in *MyServer // monitor the end of the connection go func() { conn.Wait() conn.Close() // YYY do some cleanup in *MyServer }() return jsonrpc2.ConnectionOptions{}, nil } The "// YYY do some cleanup in *MyServer" should be reached for each end of connection. If Connection.async is initialized too late, after conn.Wait() is called in the Bind() spawned goroutine, conn.Wait() never returns as it reads on a nil conn.async.ready channel. Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
@gopherbot
Copy link
Contributor

This PR (HEAD: a7fce45) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/exp/+/436888 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Maxime Soulé:

Patch Set 4:

(4 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Bryan Mills:

Patch Set 4: Run-TryBot+1 Auto-Submit+1 Code-Review+2

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Bryan Mills:

Patch Set 4: -Auto-Submit


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 4:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 4: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Maxime Soulé:

Patch Set 5:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Bryan Mills:

Patch Set 5: Run-TryBot+1 Auto-Submit+1 Code-Review+2


Please don’t reply on this GitHub thread. Visit golang.org/cl/436888.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Oct 12, 2022
If Connection.async is not initialized before calling binder.Bind() and a goroutine is spawned in binder.Bind() to monitor the end of the connection using conn.Wait(), this conn.Wait() can wait forever: func (s *MyServer) Bind( ctx context.Context, conn *jsonrpc2.Connection, ) (jsonrpc2.ConnectionOptions, error) { // XXX register conn in *MyServer // monitor the end of the connection go func() { conn.Wait() conn.Close() // YYY do some cleanup in *MyServer }() return jsonrpc2.ConnectionOptions{}, nil } The "// YYY do some cleanup in *MyServer" should be reached for each end of connection. If Connection.async is initialized too late, after conn.Wait() is called in the Bind() spawned goroutine, conn.Wait() never returns as it reads on a nil conn.async.ready channel. Fixes #56131. Change-Id: I3c6e69d7dcc860479c4518ebd18e2431606322bc GitHub-Last-Rev: a7fce45 GitHub-Pull-Request: #45 Reviewed-on: https://go-review.googlesource.com/c/exp/+/436888 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Joedian Reid <joedian@golang.org>
@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/436888 has been merged.

@gopherbot gopherbot closed this Oct 12, 2022
@maxatome maxatome deleted the fix-conn-bind branch October 12, 2022 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants