Commit 1b79b46
Fix flaky kafka tests by flushing producer before ending sender transactions (#2619)
* Initial plan
* fix: add producer.flush() to kafka tests to prevent race conditions
The producer.send() method in kafka-python is asynchronous - it queues
messages to be sent by a background I/O thread. Without calling
producer.flush(), messages may not be delivered to the Kafka broker
before the consumer's consumer_timeout_ms=500 expires. This creates a
race condition where the consumer loop exits with no items consumed,
resulting in no spans being created.
Added producer.flush() after producer.send() calls in all delayed_send
functions to ensure messages are actually delivered to Kafka.
Agent-Logs-Url: https://github.com/elastic/apm-agent-python/sessions/e5ad59a6-a44a-4dd2-978e-fe4844b5c198
Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com>
* fix: wait for kafka send futures in flaky consumer tests
Agent-Logs-Url: https://github.com/elastic/apm-agent-python/sessions/c8da0228-9a66-4391-a204-fe0b99b1b85b
Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com>
* fix: flush kafka producer before ending sender transaction
Agent-Logs-Url: https://github.com/elastic/apm-agent-python/sessions/610642ed-3a8d-4371-bccb-485eaee1d69d
Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: xrmx <12932+xrmx@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>1 parent 6a22dfa commit 1b79b46
1 file changed
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| 143 | + | |
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
| |||
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
| 171 | + | |
169 | 172 | | |
170 | 173 | | |
171 | 174 | | |
| |||
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
| 192 | + | |
189 | 193 | | |
190 | 194 | | |
191 | 195 | | |
| |||
205 | 209 | | |
206 | 210 | | |
207 | 211 | | |
| 212 | + | |
208 | 213 | | |
209 | 214 | | |
210 | 215 | | |
| |||
249 | 254 | | |
250 | 255 | | |
251 | 256 | | |
| 257 | + | |
252 | 258 | | |
253 | 259 | | |
254 | 260 | | |
| |||
0 commit comments