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 Hearbeat monitor initialization fails twice #25073

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

- Fixed excessive memory usage introduced in 7.5 due to over-allocating memory for HTTP checks. {pull}15639[15639]
- Fixed TCP TLS checks to properly validate hostnames, this broke in 7.x and only worked for IP SANs. {pull}17549[17549]
- Fix panic when initialization of ICMP monitors fail twice. {pull}25073[25073]

*Journalbeat*

Expand Down
21 changes: 13 additions & 8 deletions heartbeat/monitors/active/icmp/stdloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,25 @@ type requestResult struct {
// These vars should not be used directly, but rather getStdLoop
// should be invoked to initialize and return stdLoop.
var (
stdICMPLoopInit sync.Once
stdICMPLoopInit sync.Mutex
stdICMPLoopSingleton *stdICMPLoop
)

func getStdLoop() (*stdICMPLoop, error) {
var loopErr error
stdICMPLoopInit.Do(func() {
stdICMPLoopInit.Lock()
defer stdICMPLoopInit.Unlock()

if stdICMPLoopSingleton == nil {
debugf("initializing ICMP loop")
stdICMPLoopSingleton, loopErr = newICMPLoop()
if loopErr == nil {
debugf("ICMP loop successfully initialized")
singleton, err := newICMPLoop()
if err != nil {
return nil, err
}
})
return stdICMPLoopSingleton, loopErr
stdICMPLoopSingleton = singleton
debugf("ICMP loop successfully initialized")
}

return stdICMPLoopSingleton, nil
}

func noPingCapabilityError(message string) error {
Expand Down