Skip to content

Commit

Permalink
Fix multiple problems
Browse files Browse the repository at this point in the history
Remove erroneous blocking call to serve in grpc http server.
Return error returned by grpc server Start methods.
Fix bad peer test config.
  • Loading branch information
piersy committed Aug 17, 2023
1 parent f303787 commit 33808b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 0 additions & 1 deletion api/grpcserver/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func (s *JSONHTTPServer) StartService(
s.server = &http.Server{
Handler: mux,
}
s.server.Serve(lis)
s.grp.Go(func() error {
if err := s.server.Serve(lis); err != nil {
s.logger.Error("error from grpc http server: %v", err)
Expand Down
12 changes: 9 additions & 3 deletions node/bad_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@ func TestPeerDisconnectForMessageResultValidationReject(t *testing.T) {
conf1.DataDirParent = t.TempDir()
conf1.FileLock = filepath.Join(conf1.DataDirParent, "LOCK")
conf1.P2P.Listen = "/ip4/127.0.0.1/tcp/0"
// We setup the api to listen on an OS assigned port, which avoids the second instance getting stuck when
conf1.API.PublicListener = "0.0.0.0:0"
conf1.API.PrivateListener = "0.0.0.0:0"
app1, err := NewApp(&conf1)
require.NoError(t, err)
conf2 := config.DefaultTestConfig()

// We need to copy the genesis config to ensure that both nodes share the
// same gnenesis ID, otherwise they will not be able to connect to each
// other.
*conf2.Genesis = *conf1.Genesis
conf2.DataDirParent = t.TempDir()
conf2.FileLock = filepath.Join(conf2.DataDirParent, "LOCK")
conf2.P2P.Listen = "/ip4/127.0.0.1/tcp/0"
conf2.API.PublicListener = "0.0.0.0:0"
conf2.API.PrivateListener = "0.0.0.0:0"
app2, err := NewApp(&conf2)
require.NoError(t, err)

Expand All @@ -54,13 +60,13 @@ func TestPeerDisconnectForMessageResultValidationReject(t *testing.T) {
app1.Cleanup(ctx)
app2.Cleanup(ctx)
})
g := errgroup.Group{}
g, grpContext := errgroup.WithContext(ctx)
g.Go(func() error {
return app1.Start(ctx)
return app1.Start(grpContext)
})
<-app1.Started()
g.Go(func() error {
return app2.Start(ctx)
return app2.Start(grpContext)
})
<-app2.Started()

Expand Down
8 changes: 6 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,10 +1108,14 @@ func (app *App) startAPIServices(ctx context.Context) error {
app.jsonAPIService.StartService(ctx, public...)
}
if app.grpcPublicService != nil {
app.grpcPublicService.Start()
if err := app.grpcPublicService.Start(); err != nil {
return err
}
}
if app.grpcPrivateService != nil {
app.grpcPrivateService.Start()
if err := app.grpcPrivateService.Start(); err != nil {
return err
}
}
return nil
}
Expand Down

0 comments on commit 33808b6

Please sign in to comment.