Skip to content

Commit

Permalink
[8.16](backport #42036) [filebeat][streaming] - Fix for streaming inp…
Browse files Browse the repository at this point in the history
…ut handling of invalid or empty websocket messages (#42047)
  • Loading branch information
mergify[bot] authored Dec 18, 2024
1 parent 0647e32 commit e000a0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Upgrade azure-event-hubs-go and azure-storage-blob-go dependencies. {pull}38861[38861]
- Fix request trace filename handling in http_endpoint input. {pull}39410[39410]
- Upgrade github.com/hashicorp/go-retryablehttp to mitigate CVE-2024-6104 {pull}40036[40036]
- Fix streaming input handling of invalid or empty websocket messages. {pull}42036[42036]

*Heartbeat*

Expand Down
32 changes: 16 additions & 16 deletions x-pack/filebeat/input/streaming/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@ func (s *websocketStream) FollowStream(ctx context.Context) error {
_, message, err := c.ReadMessage()
if err != nil {
s.metrics.errorsTotal.Inc()
if isRetryableError(err) {
s.log.Debugw("websocket connection encountered an error, attempting to reconnect...", "error", err)
// close the old connection and reconnect
if err := c.Close(); err != nil {
s.metrics.errorsTotal.Inc()
s.log.Errorw("encountered an error while closing the websocket connection", "error", err)
}
// since c is already a pointer, we can reassign it to the new connection and the defer func will still handle it
c, resp, err = connectWebSocket(ctx, s.cfg, url, s.log)
handleConnectionResponse(resp, s.metrics, s.log)
if err != nil {
s.metrics.errorsTotal.Inc()
s.log.Errorw("failed to reconnect websocket connection", "error", err)
return err
}
} else {
if !isRetryableError(err) {
s.log.Errorw("failed to read websocket data", "error", err)
return err
}
s.log.Debugw("websocket connection encountered an error, attempting to reconnect...", "error", err)
// close the old connection and reconnect
if err := c.Close(); err != nil {
s.metrics.errorsTotal.Inc()
s.log.Errorw("encountered an error while closing the websocket connection", "error", err)
}
// since c is already a pointer, we can reassign it to the new connection and the defer func will still handle it
c, resp, err = connectWebSocket(ctx, s.cfg, url, s.log)
handleConnectionResponse(resp, s.metrics, s.log)
if err != nil {
s.metrics.errorsTotal.Inc()
s.log.Errorw("failed to reconnect websocket connection", "error", err)
return err
}
continue
}
s.metrics.receivedBytesTotal.Add(uint64(len(message)))
state["response"] = message
Expand Down

0 comments on commit e000a0c

Please sign in to comment.