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

Ensure Zipkin shutdown correctness #2765

Merged
merged 4 commits into from
Mar 23, 2021

Conversation

pjanotti
Copy link
Contributor

Description:
Zipkin shutdown method was returning before its server goroutine was completed and not checking for the expected http.ErrServerClosed. This PR ensures shutdown only returns after the goroutine completes, no errors are reported when the server is closed. Opportunistic fix: remove an improper call to ReportFatalError for a synchronous error when the port is already in use.

Testing:
Enabled lifecycle test for Zipkin receiver.

@pjanotti pjanotti requested a review from a team March 22, 2021 23:54
@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #2765 (294ba99) into main (73dfd89) will decrease coverage by 0.01%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2765      +/-   ##
==========================================
- Coverage   91.80%   91.79%   -0.02%     
==========================================
  Files         291      291              
  Lines       15528    15529       +1     
==========================================
- Hits        14256    14255       -1     
- Misses        869      870       +1     
- Partials      403      404       +1     
Impacted Files Coverage Δ
receiver/otlpreceiver/otlp.go 88.67% <0.00%> (ø)
receiver/zipkinreceiver/trace_receiver.go 90.47% <60.00%> (-1.84%) ⬇️
receiver/opencensusreceiver/opencensus.go 89.10% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73dfd89...294ba99. Read the comment docs.

err = zr.server.Serve(listener)
if err != nil {
if err != nil && err != http.ErrServerClosed {
Copy link
Member

Choose a reason for hiding this comment

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

See https://golang.org/pkg/net/http/#Server.Serve it never returns nil.

if errHTTP := zr.server.Serve(listene); errHTTP != http.ErrServerClosed {
  host.ReportFatalError(err)
}

May worth changing the OTLP if you want to not spam the ReportFatalError logs.

Copy link
Member

Choose a reason for hiding this comment

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

Actually it is an "and" so just unnecessary extra protection.

Copy link
Contributor Author

@pjanotti pjanotti Mar 23, 2021

Choose a reason for hiding this comment

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

Yeah, will remove the check for error nil for HTTP server. For grpc the docs imply that it can actually return nil: "Serve will return a non-nil error unless Stop or GracefulStop is called." Looking at the sources it can definitely return nil. https://github.com/grpc/grpc-go/blob/v1.36.0/server.go#L768

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -99,12 +100,14 @@ func (zr *ZipkinReceiver) Start(ctx context.Context, host component.Host) error
var listener net.Listener
listener, err = zr.config.HTTPServerSettings.ToListener()
if err != nil {
host.ReportFatalError(err)
Copy link
Member

Choose a reason for hiding this comment

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

Nice

return
}
zr.shutdownCh = make(chan struct{})
Copy link
Member

Choose a reason for hiding this comment

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

Use waitgroup, so an easy "refactoring" can be done and allow helper to provide this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea... done.

@bogdandrutu bogdandrutu merged commit c7e9b68 into open-telemetry:main Mar 23, 2021
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