-
Notifications
You must be signed in to change notification settings - Fork 518
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 panic when a signal is delivered before the server is instantiated #580
Changes from 2 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 |
---|---|---|
|
@@ -7,14 +7,18 @@ import ( | |
"net/http" | ||
"regexp" | ||
|
||
"sync" | ||
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. not sure how this is getting through the 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 always have this problem, this is how it looks after running |
||
|
||
"github.com/elastic/beats/libbeat/beat" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
) | ||
|
||
type beater struct { | ||
config *Config | ||
server *http.Server | ||
config *Config | ||
server *http.Server | ||
mutex sync.RWMutex | ||
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.
|
||
stopped bool | ||
} | ||
|
||
// Creates beater | ||
|
@@ -36,7 +40,8 @@ func New(b *beat.Beat, ucfg *common.Config) (beat.Beater, error) { | |
} | ||
|
||
bt := &beater{ | ||
config: beaterConfig, | ||
config: beaterConfig, | ||
stopped: false, | ||
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 like this being explicit 👍 |
||
} | ||
return bt, nil | ||
} | ||
|
@@ -57,7 +62,14 @@ func (bt *beater) Run(b *beat.Beat) error { | |
} | ||
go notifyListening(bt.config, pub.Send) | ||
|
||
bt.mutex.Lock() | ||
if bt.stopped { | ||
defer bt.mutex.Unlock() | ||
return nil | ||
} | ||
|
||
bt.server = newServer(bt.config, pub.Send) | ||
bt.mutex.Unlock() | ||
|
||
err = run(bt.server, lis, bt.config) | ||
if err == http.ErrServerClosed { | ||
|
@@ -70,5 +82,10 @@ func (bt *beater) Run(b *beat.Beat) error { | |
// Graceful shutdown | ||
func (bt *beater) Stop() { | ||
logp.Info("stopping apm-server...") | ||
stop(bt.server, bt.config.ShutdownTimeout) | ||
bt.mutex.Lock() | ||
if bt.server != nil { | ||
stop(bt.server, bt.config.ShutdownTimeout) | ||
} | ||
bt.stopped = true | ||
bt.mutex.Unlock() | ||
} |
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.
Bit of a nitpick but we currently catch
INT
andTERM
, maybe justsignal
instead?