Skip to content

Commit

Permalink
Shutdown everytime http server starts to fail to clean up GRPC server
Browse files Browse the repository at this point in the history
  • Loading branch information
crobert-1 committed Jan 8, 2024
1 parent 60d44f5 commit 31feb8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 0 additions & 3 deletions receiver/otlpreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func TestCreateTracesReceiver(t *testing.T) {
assert.NoError(t, err)
if tt.wantStartErr {
assert.Error(t, tr.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, tr.Shutdown(context.Background()))
} else {
assert.NoError(t, tr.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, tr.Shutdown(context.Background()))
Expand Down Expand Up @@ -261,7 +260,6 @@ func TestCreateMetricReceiver(t *testing.T) {
assert.NoError(t, err)
if tt.wantStartErr {
assert.Error(t, mr.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, mr.Shutdown(context.Background()))
} else {
require.NoError(t, mr.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, mr.Shutdown(context.Background()))
Expand Down Expand Up @@ -371,7 +369,6 @@ func TestCreateLogReceiver(t *testing.T) {
assert.NoError(t, err)
if tt.wantStartErr {
assert.Error(t, mr.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, mr.Shutdown(context.Background()))
} else {
require.NoError(t, mr.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, mr.Shutdown(context.Background()))
Expand Down
7 changes: 6 additions & 1 deletion receiver/otlpreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"sync"

"go.uber.org/multierr"
"go.uber.org/zap"
"google.golang.org/grpc"

Expand Down Expand Up @@ -168,11 +169,15 @@ func (r *otlpReceiver) startHTTPServer(host component.Host) error {

// Start runs the trace receiver on the gRPC server. Currently
// it also enables the metrics receiver too.
func (r *otlpReceiver) Start(_ context.Context, host component.Host) error {
func (r *otlpReceiver) Start(ctx context.Context, host component.Host) error {
if err := r.startGRPCServer(host); err != nil {
return err
}
if err := r.startHTTPServer(host); err != nil {
// It's possible that a valid GRPC server configuration was specified,
// but an invalid HTTP configuration. If that's the case, the successfully
// started GRPC server must be shutdown to ensure no goroutines are leaked.
err = multierr.Append(err, r.Shutdown(ctx))
return err
}

Expand Down

0 comments on commit 31feb8e

Please sign in to comment.