Commit 10e7785
committed
fluent: make connection closed variable thread-safe
Changed the "closed" variable to be an atomic int. There is a race condition b/w
appendBuffer and Close() method wrt how this variable is accessed. This could be
an atomic.Bool, but the CI/CD config uses golang version 1.17. Since atomic.Bool
is supported 1.19 onwards, using that would fail tests and build.
Data race trace without this fix (using `go test -race`):
==================
WARNING: DATA RACE
Write at 0x00c0003324e0 by goroutine 95:
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).close()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent.go:426 +0x13c
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).Close()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent.go:393 +0x108
github.com/fluent/fluent-logger-golang/fluent.TestCloseWhileWaitingForAckResponse.func1()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent_test.go:737 +0x2c
github.com/fluent/fluent-logger-golang/fluent.timeout.func1()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent_test.go:557 +0x38
Previous read at 0x00c0003324e0 by goroutine 94:
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).write()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent.go:619 +0x1ac
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).writeWithRetry()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent.go:553 +0x78
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).run()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent.go:527 +0x1d0
github.com/fluent/fluent-logger-golang/fluent.newWithDialer.gowrap1()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent.go:184 +0x4c
Goroutine 95 (running) created at:
github.com/fluent/fluent-logger-golang/fluent.timeout()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent_test.go:556 +0xe8
github.com/fluent/fluent-logger-golang/fluent.TestCloseWhileWaitingForAckResponse()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent_test.go:736 +0x444
testing.tRunner()
/opt/homebrew/Cellar/go/1.24.2/libexec/src/testing/testing.go:1792 +0x180
testing.(*T).Run.gowrap1()
/opt/homebrew/Cellar/go/1.24.2/libexec/src/testing/testing.go:1851 +0x40
Goroutine 94 (running) created at:
github.com/fluent/fluent-logger-golang/fluent.newWithDialer()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent.go:184 +0x368
github.com/fluent/fluent-logger-golang/fluent.TestCloseWhileWaitingForAckResponse()
/Users/aithal/workspace/src/github.com/aaithal/fluent-logger-golang/fluent/fluent_test.go:722 +0xd8
testing.tRunner()
/opt/homebrew/Cellar/go/1.24.2/libexec/src/testing/testing.go:1792 +0x180
testing.(*T).Run.gowrap1()
/opt/homebrew/Cellar/go/1.24.2/libexec/src/testing/testing.go:1851 +0x40
==================
[2025-05-06T08:42:08-07:00] Discarding queued events...
testing.go:1490: race detected during execution of test
Signed-off-by: Anirudh Aithal <aithal@amazon.com>1 parent f1b233b commit 10e7785
1 file changed
+37
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
117 | | - | |
118 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
176 | 181 | | |
177 | 182 | | |
178 | 183 | | |
179 | | - | |
180 | 184 | | |
| 185 | + | |
181 | 186 | | |
182 | 187 | | |
183 | 188 | | |
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
187 | | - | |
188 | | - | |
189 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
190 | 196 | | |
191 | 197 | | |
192 | 198 | | |
| |||
290 | 296 | | |
291 | 297 | | |
292 | 298 | | |
293 | | - | |
| 299 | + | |
294 | 300 | | |
295 | 301 | | |
296 | 302 | | |
| |||
367 | 373 | | |
368 | 374 | | |
369 | 375 | | |
| 376 | + | |
370 | 377 | | |
371 | | - | |
| 378 | + | |
| 379 | + | |
372 | 380 | | |
373 | 381 | | |
374 | 382 | | |
375 | | - | |
376 | | - | |
| 383 | + | |
377 | 384 | | |
378 | 385 | | |
379 | 386 | | |
380 | 387 | | |
381 | 388 | | |
382 | 389 | | |
| 390 | + | |
| 391 | + | |
383 | 392 | | |
384 | 393 | | |
385 | 394 | | |
| |||
391 | 400 | | |
392 | 401 | | |
393 | 402 | | |
394 | | - | |
| 403 | + | |
395 | 404 | | |
396 | 405 | | |
397 | 406 | | |
| |||
406 | 415 | | |
407 | 416 | | |
408 | 417 | | |
409 | | - | |
410 | | - | |
411 | | - | |
| 418 | + | |
412 | 419 | | |
413 | 420 | | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
414 | 431 | | |
415 | 432 | | |
416 | 433 | | |
| |||
610 | 627 | | |
611 | 628 | | |
612 | 629 | | |
| 630 | + | |
| 631 | + | |
613 | 632 | | |
614 | 633 | | |
615 | 634 | | |
| |||
619 | 638 | | |
620 | 639 | | |
621 | 640 | | |
| 641 | + | |
622 | 642 | | |
623 | 643 | | |
624 | 644 | | |
| |||
0 commit comments