Skip to content

Commit 7cdb0e7

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
internal/jsonrpc2_v2: rename Serve to NewServer and eliminate its error return
Serve had a misleading name and signature: it did not actually block on serving the connection, and never returned a non-nil error. Updates golang/go#56281. Change-Id: Ia6df0ba20066811b0551df3b3267dff2fffd7881 Reviewed-on: https://go-review.googlesource.com/c/tools/+/443678 Reviewed-by: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
1 parent 28e9e50 commit 7cdb0e7

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

gopls/internal/lsp/lsprpc/binder_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ func (e *TestEnv) serve(ctx context.Context, t *testing.T, server jsonrpc2_v2.Bi
4343
if err != nil {
4444
t.Fatal(err)
4545
}
46-
s, err := jsonrpc2_v2.Serve(ctx, l, server)
47-
if err != nil {
48-
l.Close()
49-
t.Fatal(err)
50-
}
46+
s := jsonrpc2_v2.NewServer(ctx, l, server)
5147
e.Servers = append(e.Servers, s)
5248
return l, s
5349
}

internal/jsonrpc2_v2/jsonrpc2_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ func testConnection(t *testing.T, framer jsonrpc2.Framer) {
136136
if err != nil {
137137
t.Fatal(err)
138138
}
139-
server, err := jsonrpc2.Serve(ctx, listener, binder{framer, nil})
140-
if err != nil {
141-
t.Fatal(err)
142-
}
139+
server := jsonrpc2.NewServer(ctx, listener, binder{framer, nil})
143140
defer func() {
144141
listener.Close()
145142
server.Wait()

internal/jsonrpc2_v2/serve.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ func Dial(ctx context.Context, dialer Dialer, binder Binder) (*Connection, error
6363
return newConnection(ctx, rwc, binder, nil), nil
6464
}
6565

66-
// Serve starts a new server listening for incoming connections and returns
66+
// NewServer starts a new server listening for incoming connections and returns
6767
// it.
6868
// This returns a fully running and connected server, it does not block on
6969
// the listener.
7070
// You can call Wait to block on the server, or Shutdown to get the sever to
7171
// terminate gracefully.
7272
// To notice incoming connections, use an intercepting Binder.
73-
func Serve(ctx context.Context, listener Listener, binder Binder) (*Server, error) {
73+
func NewServer(ctx context.Context, listener Listener, binder Binder) *Server {
7474
server := &Server{
7575
listener: listener,
7676
binder: binder,
7777
async: newAsync(),
7878
}
7979
go server.run(ctx)
80-
return server, nil
80+
return server
8181
}
8282

8383
// Wait returns only when the server has shut down.

internal/jsonrpc2_v2/serve_test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ func TestIdleTimeout(t *testing.T) {
4141
listener = jsonrpc2.NewIdleListener(d, listener)
4242
defer listener.Close()
4343

44-
server, err := jsonrpc2.Serve(ctx, listener, jsonrpc2.ConnectionOptions{})
45-
if err != nil {
46-
t.Fatal(err)
47-
}
44+
server := jsonrpc2.NewServer(ctx, listener, jsonrpc2.ConnectionOptions{})
4845

4946
// Exercise some connection/disconnection patterns, and then assert that when
5047
// our timer fires, the server exits.
@@ -187,12 +184,9 @@ func TestServe(t *testing.T) {
187184
}
188185

189186
func newFake(t *testing.T, ctx context.Context, l jsonrpc2.Listener) (*jsonrpc2.Connection, func(), error) {
190-
server, err := jsonrpc2.Serve(ctx, l, jsonrpc2.ConnectionOptions{
187+
server := jsonrpc2.NewServer(ctx, l, jsonrpc2.ConnectionOptions{
191188
Handler: fakeHandler{},
192189
})
193-
if err != nil {
194-
return nil, nil, err
195-
}
196190

197191
client, err := jsonrpc2.Dial(ctx,
198192
l.Dialer(),
@@ -288,7 +282,7 @@ func TestCloseCallRace(t *testing.T) {
288282

289283
pokec := make(chan *jsonrpc2.AsyncCall, 1)
290284

291-
s, err := jsonrpc2.Serve(ctx, listener, jsonrpc2.BinderFunc(func(_ context.Context, srvConn *jsonrpc2.Connection) jsonrpc2.ConnectionOptions {
285+
s := jsonrpc2.NewServer(ctx, listener, jsonrpc2.BinderFunc(func(_ context.Context, srvConn *jsonrpc2.Connection) jsonrpc2.ConnectionOptions {
292286
h := jsonrpc2.HandlerFunc(func(ctx context.Context, _ *jsonrpc2.Request) (interface{}, error) {
293287
// Start a concurrent call from the server to the client.
294288
// The point of this test is to ensure this doesn't deadlock
@@ -305,10 +299,6 @@ func TestCloseCallRace(t *testing.T) {
305299
})
306300
return jsonrpc2.ConnectionOptions{Handler: h}
307301
}))
308-
if err != nil {
309-
listener.Close()
310-
t.Fatal(err)
311-
}
312302

313303
dialConn, err := jsonrpc2.Dial(ctx, listener.Dialer(), jsonrpc2.ConnectionOptions{})
314304
if err != nil {

0 commit comments

Comments
 (0)