-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix address already in use with webhooks input during reload #3206
Conversation
Change HTTP lister, to implement Close() method and avoid displaying error by adding condition based on `http.ErrServerClosed` error.
plugins/inputs/webhooks/webhooks.go
Outdated
|
||
ln, err := net.Listen("tcp", fmt.Sprintf("%s", wb.ServiceAddress)) | ||
if err != nil { | ||
acc.AddError(fmt.Errorf("E! Error starting server: %v", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should return this error, making it fatal and preventing Telegraf from starting. This probably indicates the port is in use or a privilege issue, and won't resolve, so I think exit is the right action even though it is technically a change in behavior.
plugins/inputs/webhooks/webhooks.go
Outdated
err := http.ListenAndServe(fmt.Sprintf("%s", wb.ServiceAddress), r) | ||
if err != nil { | ||
acc.AddError(fmt.Errorf("E! Error starting server: %v", err)) | ||
func (wb *Webhooks) listen(ln net.Listener, acc telegraf.Accumulator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets call this serve
since we are already listening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just inline it in the Start
func.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Move content of listen() function to inline function inside Start() function. Report fatal and return from Start() function (exit program) in case where net.Listen() has any problem.
@dankans thanks! |
Thanks @danielnelson and @francois2metz for help! |
Change HTTP listener by removing
ListenAndServe()
method and implementingClose() net.Listen()
methods.Change error reporting, by disabling adding it in case when
http.ErrServerClosed
occurred.Required for all PRs: