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

Add QUIC RPC server and client #2519

Merged
merged 2 commits into from
Mar 13, 2019
Merged

Add QUIC RPC server and client #2519

merged 2 commits into from
Mar 13, 2019

Conversation

scrye
Copy link
Contributor

@scrye scrye commented Mar 13, 2019

This change is Reviewable

@scrye scrye self-assigned this Mar 13, 2019
@scrye scrye requested a review from lukedirtwalker March 13, 2019 11:34
Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1.
Reviewable status: all files reviewed, 18 unresolved discussions (waiting on @scrye)


go/lib/infra/rpc/BUILD.bazel, line 17 at r1 (raw file):

        "//go/lib/snet:go_default_library",
        "//go/proto:go_default_library",
        "@com_github_lucas_clemente_quic_go//:go_default_library",

We still v0.8.0 would it make sense to upgrade? or did nothing relevant change?


go/lib/infra/rpc/request.go, line 15 at r1 (raw file):

// limitations under the License.

package rpc

I think the package needs a doc string.


go/lib/infra/rpc/rpc.go, line 35 at r1 (raw file):

const (
	CtxTimedOutError = iota + 1

Explain what this is. It is the error code for a context timeout while writing.


go/lib/infra/rpc/rpc.go, line 61 at r1 (raw file):

		return err
	}
	for {

Is there a clean way to tear this down?


go/lib/infra/rpc/rpc.go, line 64 at r1 (raw file):

		session, err := s.listener.Accept()
		if err != nil {
			if strings.Contains(err.Error(), "use of closed network connection") {

Why do we need to return here and not for other errors?


go/lib/infra/rpc/rpc.go, line 67 at r1 (raw file):

				return err
			}
			log.Warn("server accept error", "err", err)

I think it would make sense to prefix log messages with [quic]


go/lib/infra/rpc/rpc.go, line 91 at r1 (raw file):

}

func (s *Server) Close() error {

Maybe explain what close does.


go/lib/infra/rpc/rpc.go, line 136 at r1 (raw file):

}

func (c *Client) Request(ctx context.Context, request *Request, address net.Addr) (*Reply, error) {

Add a doc. Request sends the requests and blocks until the reply is back for example.


go/lib/infra/rpc/rpc.go, line 151 at r1 (raw file):

	go func() {
		<-ctx.Done()
		stream.CancelWrite(CtxTimedOutError)

Does that work on a closed stream?


go/lib/infra/rpc/rpc.go, line 202 at r1 (raw file):

// ReplyWriter provides handlers a way to respond to requests. ReplyWriter
// keeps a connection alive for replying. To force cleanup of the connection,
// call Close.

It isn't clear to me whether I need to call or not?


go/lib/infra/rpc/rpc.go, line 226 at r1 (raw file):

	}

	err = rw.stream.Close()

Why does this also call close?


go/lib/infra/rpc/rpc_test.go, line 38 at r1 (raw file):

	err := rw.WriteReply(reply)
	if err != nil {
		log.Warn("serve error", "err", err)

I wonder if it would make sense to have a t (testing.TB) reference in handler and use xtest.FailOnErr here?


go/lib/infra/rpc/rpc_test.go, line 49 at r1 (raw file):

func TestServer(t *testing.T) {
	Convey("Given a server", t, func() {
		cliConn, srvConn := getTestUDPConns(t, 60000, 60001)

I'd do that outside the convey block to make sure it is really only executed once.


go/lib/infra/rpc/rpc_test.go, line 81 at r1 (raw file):

			err := server.ListenAndServe()
			if err != nil {
				t.Fatalf("server err = %v\n", err)

xtest.FailOnErr


go/lib/infra/rpc/rpc_test.go, line 85 at r1 (raw file):

		}()
		reply, err := client.Request(
			context.Background(),

you could do a global timeout variable like 1s or something and use a context with timeout here. It prevents the test to run longer than it needs if stuff doesn't work.


go/lib/infra/rpc/rpc_test.go, line 90 at r1 (raw file):

		)
		if err != nil {
			t.Fatalf("client err = %v\n", err)

xtest.FailOnErr


go/lib/infra/rpc/rpc_test.go, line 104 at r1 (raw file):

t testing.TB

TIL about TB. We should use that in our xtest package.


go/lib/infra/rpc/rpc_test.go, line 130 at r1 (raw file):

	srvConn, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: srvPort})
	if err != nil {
		t.Fatalf("server listen err = %v\n", err)

xtest.FailOnErr


go/lib/infra/rpc/rpc_test.go, line 134 at r1 (raw file):

	cliConn, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: cliPort})
	if err != nil {
		t.Fatalf("client listen err = %v\n", err)

xtest.FailOnErr

Copy link
Contributor Author

@scrye scrye left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 18 unresolved discussions (waiting on @lukedirtwalker)


go/lib/infra/rpc/BUILD.bazel, line 17 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

We still v0.8.0 would it make sense to upgrade? or did nothing relevant change?

There are quite a lot of changes in the newer versions (including a few API ones). We definitely need to upgrade at some point, but I'd do it as a stand-alone PR.


go/lib/infra/rpc/request.go, line 15 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I think the package needs a doc string.

Done, but in rpc.go; I think it fits better there.


go/lib/infra/rpc/rpc.go, line 35 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Explain what this is. It is the error code for a context timeout while writing.

Done.


go/lib/infra/rpc/rpc.go, line 61 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Is there a clean way to tear this down?

Calling Close is the way to tear it down (closing the network connection is how most of these types of servers are closed, e.g., the standard library's http server).


go/lib/infra/rpc/rpc.go, line 64 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Why do we need to return here and not for other errors?

Other errors might be related to a specific Accept that somehow failed, but does not affect future Accepts. For closed network connection we need to exit because this is how the server shuts down.


go/lib/infra/rpc/rpc.go, line 67 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I think it would make sense to prefix log messages with [quic]

Done.


go/lib/infra/rpc/rpc.go, line 91 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Maybe explain what close does.

Done.


go/lib/infra/rpc/rpc.go, line 136 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Add a doc. Request sends the requests and blocks until the reply is back for example.

Done.


go/lib/infra/rpc/rpc.go, line 151 at r1 (raw file):
Yes, it's mentioned explicitly in the docs:

// Write will unblock immediately, and future calls to Write will fail.
// When called multiple times or after closing the stream it is a no-op.

go/lib/infra/rpc/rpc.go, line 202 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

It isn't clear to me whether I need to call or not?

Added some docs, hopefully this clear it up a bit.


go/lib/infra/rpc/rpc.go, line 226 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Why does this also call close?

The external Close is for callers needing to unblock the writer. This is because some callers (e.g., our handlers in infra) have contexts they need to respect, but there is no direct way to interact with the underlying conn.


go/lib/infra/rpc/rpc_test.go, line 38 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I wonder if it would make sense to have a t (testing.TB) reference in handler and use xtest.FailOnErr here?

Done.


go/lib/infra/rpc/rpc_test.go, line 49 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I'd do that outside the convey block to make sure it is really only executed once.

I specifically wanted it inside to have as few side effects as possible between the Convey branches.


go/lib/infra/rpc/rpc_test.go, line 81 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

xtest.FailOnErr

Done.


go/lib/infra/rpc/rpc_test.go, line 85 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

you could do a global timeout variable like 1s or something and use a context with timeout here. It prevents the test to run longer than it needs if stuff doesn't work.

Done.


go/lib/infra/rpc/rpc_test.go, line 90 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

xtest.FailOnErr

Done.


go/lib/infra/rpc/rpc_test.go, line 104 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…
t testing.TB

TIL about TB. We should use that in our xtest package.

I changed them as part of this PR, it was easy.


go/lib/infra/rpc/rpc_test.go, line 130 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

xtest.FailOnErr

Done.


go/lib/infra/rpc/rpc_test.go, line 134 at r1 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

xtest.FailOnErr

Done.

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 4 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@scrye scrye merged commit 73c1f55 into scionproto:master Mar 13, 2019
@scrye scrye deleted the pubpr-quicrpc-lib branch March 13, 2019 14:18
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