Skip to content

Commit 74c8625

Browse files
[8.17](backport #44342) [filebeat][streaming] - Fixed a websocket panic scenario which would occur after exhausting max retries (#44389)
* [filebeat][streaming] - Fixed a websocket panic scenario which would occur after exhausting max retries (#44342) In some scenarios the websocket response object can become nil and cause certain logging statements to cause an unexpected panic. This PR fixes once such identified scenario. (cherry picked from commit f6994c0) * Update CHANGELOG.next.asciidoc --------- Co-authored-by: Shourie Ganguly <shourie.ganguly@elastic.co>
1 parent 101a209 commit 74c8625

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
114114
- Fix publication of group data from the Okta entity analytics provider. {pull}40681[40681]
115115
- Ensure netflow custom field configuration is applied. {issue}40735[40735] {pull}40730[40730]
116116
- Fix a bug in Salesforce input to only handle responses with 200 status code {pull}41015[41015]
117+
- Fixed a websocket panic scenario which would occur after exhausting max retries. {pull}44342[44342]
117118

118119
*Heartbeat*
119120

x-pack/filebeat/input/streaming/input_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ var inputTests = []struct {
127127
"events": [inner_body],
128128
})`,
129129
},
130-
response: []string{`
130+
response: []string{
131+
`
131132
{
132133
"pps": {
133134
"agent": "example.proofpoint.com",
@@ -177,7 +178,8 @@ var inputTests = []struct {
177178
"pri": 35342
178179
},
179180
"id": "ZeYGULpZmL5N0151HN1OyX"
180-
}`},
181+
}`,
182+
},
181183
want: []map[string]interface{}{
182184
{
183185
"pps": map[string]interface{}{
@@ -278,7 +280,8 @@ var inputTests = []struct {
278280
},
279281
},
280282
},
281-
response: []string{`
283+
response: []string{
284+
`
282285
{
283286
"pps": {
284287
"agent": "example.proofpoint.com",
@@ -317,7 +320,8 @@ var inputTests = []struct {
317320
"basic_token": basicToken,
318321
},
319322
},
320-
response: []string{`
323+
response: []string{
324+
`
321325
{
322326
"pps": {
323327
"agent": "example.proofpoint.com",
@@ -349,7 +353,8 @@ var inputTests = []struct {
349353
"bearer_token": bearerToken,
350354
},
351355
},
352-
response: []string{`
356+
response: []string{
357+
`
353358
{
354359
"pps": {
355360
"agent": "example.proofpoint.com",
@@ -384,7 +389,8 @@ var inputTests = []struct {
384389
},
385390
},
386391
},
387-
response: []string{`
392+
response: []string{
393+
`
388394
{
389395
"pps": {
390396
"agent": "example.proofpoint.com",
@@ -418,7 +424,8 @@ var inputTests = []struct {
418424
"wait_max": "2s",
419425
},
420426
},
421-
response: []string{`
427+
response: []string{
428+
`
422429
{
423430
"pps": {
424431
"agent": "example.proofpoint.com",
@@ -815,7 +822,6 @@ func TestURLEval(t *testing.T) {
815822
logp.TestingSetup()
816823
for _, test := range urlEvalTests {
817824
t.Run(test.name, func(t *testing.T) {
818-
819825
cfg := conf.MustNewConfigFrom(test.config)
820826

821827
conf := config{}

x-pack/filebeat/input/streaming/websocket.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ func connectWebSocket(ctx context.Context, cfg config, url string, log *logp.Log
332332
waitTime := calculateWaitTime(retryConfig.WaitMin, retryConfig.WaitMax, attempt)
333333
time.Sleep(waitTime)
334334
}
335+
if response == nil {
336+
return nil, nil, fmt.Errorf("failed to establish WebSocket connection after %d attempts with error %w", retryConfig.MaxAttempts, err)
337+
}
335338
return nil, nil, fmt.Errorf("failed to establish WebSocket connection after %d attempts with error %w and (status %d)", retryConfig.MaxAttempts, err, response.StatusCode)
336339
} else {
337340
for attempt := 1; ; attempt++ {

0 commit comments

Comments
 (0)