-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[extension/httpforwarder] Shutdown should wait server exit #37735
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "io" | ||
| "net/http" | ||
| "net/url" | ||
| "sync" | ||
|
|
||
| "go.opentelemetry.io/collector/component" | ||
| "go.opentelemetry.io/collector/component/componentstatus" | ||
|
|
@@ -23,6 +24,7 @@ type httpForwarder struct { | |
| server *http.Server | ||
| settings component.TelemetrySettings | ||
| config *Config | ||
| shutdownWG sync.WaitGroup | ||
| } | ||
|
|
||
| var _ extension.Extension = (*httpForwarder)(nil) | ||
|
|
@@ -47,7 +49,9 @@ func (h *httpForwarder) Start(ctx context.Context, host component.Host) error { | |
| return fmt.Errorf("failed to create HTTP Client: %w", err) | ||
| } | ||
|
|
||
| h.shutdownWG.Add(1) | ||
| go func() { | ||
| defer h.shutdownWG.Done() | ||
|
dmitryax marked this conversation as resolved.
|
||
| if errHTTP := h.server.Serve(listener); !errors.Is(errHTTP, http.ErrServerClosed) && errHTTP != nil { | ||
| componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(errHTTP)) | ||
| } | ||
|
|
@@ -60,7 +64,9 @@ func (h *httpForwarder) Shutdown(_ context.Context) error { | |
| if h.server == nil { | ||
| return nil | ||
| } | ||
| return h.server.Close() | ||
| err := h.server.Close() | ||
| h.shutdownWG.Wait() | ||
| return err | ||
|
Comment on lines
+67
to
+69
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of I tend to prefer
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may miss something:
A.k.a because it returns the error from the listener that function that you wait for it must be done.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take into account the possible interleaves of the calls to While this may be rather improbable in practice, it is better for the component to behave deterministically with the shutdown ensuring no left over goroutine and/or port.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bogdandrutu PTAL at reply above |
||
| } | ||
|
|
||
| func (h *httpForwarder) forwardRequest(writer http.ResponseWriter, request *http.Request) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.