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

Fix panic when a signal is delivered before the server is instantiated #580

Merged
merged 4 commits into from
Feb 1, 2018

Conversation

jalvz
Copy link
Contributor

@jalvz jalvz commented Jan 30, 2018

Introduce a flag and a mutex in the beater so that we can't stop the server before assigning it (ie. read before write)

fixes #514

Juan A added 2 commits January 30, 2018 15:36
@@ -20,7 +20,8 @@ https://github.com/elastic/apm-server/compare/71df0d96445df35afe27f38bcf734a0828
==== Bug fixes
- Updated systemd doc url {pull}354[354]
- Updated readme doc urls {pull}356[356]
- Use updated stack trace frame values for calculating error `grouping_keys` {pull}485[485]
- Use updated stack trace frame values for calculating error `grouping_keys` {pull}485[485]
- Fix panic when a SIGINT is delivered before the server is instantiated {pull}580[580]
Copy link
Member

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 and TERM, maybe just signal instead?

beater/beater.go Outdated
@@ -7,14 +7,18 @@ import (
"net/http"
"regexp"

"sync"
Copy link
Member

Choose a reason for hiding this comment

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

not sure how this is getting through the make check - can you group this with the other stdlib imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always have this problem, this is how it looks after running gofmt and goimports. Eventually got tired of fixing white lines in import blocks manually... it might be because of my IDE, but make check seems to be happy with this indeed.

beater/beater.go Outdated
server *http.Server
config *Config
server *http.Server
mutex sync.RWMutex
Copy link
Member

Choose a reason for hiding this comment

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

mutex is guarding both server and stopped - can you move it above and add a comment to that effect like here?

@@ -36,7 +40,8 @@ func New(b *beat.Beat, ucfg *common.Config) (beat.Beater, error) {
}

bt := &beater{
config: beaterConfig,
config: beaterConfig,
stopped: false,
Copy link
Member

Choose a reason for hiding this comment

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

I like this being explicit 👍

@jalvz
Copy link
Contributor Author

jalvz commented Jan 31, 2018

thanks Gil, comments addressed here 0731cbe

beater/beater.go Outdated
config *Config
server *http.Server
config *Config
mutex sync.RWMutex // guards server and stopped
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for a RWMutex if RLock and RUnlock isn't used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, good point

@graphaelli graphaelli changed the title Fix panic when a SIGINT is delivered before the server is instantiated Fix panic when a signal is delivered before the server is instantiated Jan 31, 2018
@jalvz jalvz merged commit 28fba6d into elastic:master Feb 1, 2018
jalvz added a commit that referenced this pull request Feb 1, 2018
#580)

Introduce a flag and a mutex in the beater so that we can't stop the server before assigning it (ie. read before write)
fixes #514
jalvz added a commit that referenced this pull request Feb 1, 2018
#580)

Introduce a flag and a mutex in the beater so that we can't stop the server before assigning it (ie. read before write)
fixes #514
jalvz added a commit to jalvz/apm-server that referenced this pull request Feb 1, 2018
elastic#580)

Introduce a flag and a mutex in the beater so that we can't stop the server before assigning it (ie. read before write)
fixes elastic#514
jalvz added a commit to jalvz/apm-server that referenced this pull request Feb 1, 2018
elastic#580)

Introduce a flag and a mutex in the beater so that we can't stop the server before assigning it (ie. read before write)
fixes elastic#514
jalvz added a commit to jalvz/apm-server that referenced this pull request Feb 1, 2018
elastic#580)

Introduce a flag and a mutex in the beater so that we can't stop the server before assigning it (ie. read before write)
fixes elastic#514
jalvz added a commit to jalvz/apm-server that referenced this pull request Feb 1, 2018
elastic#580)

Introduce a flag and a mutex in the beater so that we can't stop the server before assigning it (ie. read before write)
fixes elastic#514
@jalvz jalvz deleted the fix-quick-stop-race branch February 21, 2018 08:13
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.

panic on signal during startup
3 participants