Repository navigation
Commit 308d246
fix(sources): prevent windows_event_log permanent freeze from signal-event lost wakeup (#25195)
* fix(windows_event_log): fix pre-drain ResetEvent race and add lost-wakeup regression tests
The Windows Event Log service signals the pull-mode wait handle via SetEvent
each time a new matching event is recorded. Because the handle is manual-reset,
any SetEvent that fires between the last EvtNext call and the post-drain
ResetEvent is silently lost — the subscription then hangs until the next OS
event arrives (#25194).
Fix: reset the handle *before* entering the drain loop. Signals raised during
the drain are preserved because SetEvent on an already-signaled handle is a
no-op. Re-arm (SetEvent) on early exits so the next pull_events revisits the
channel without waiting for a fresh OS notification:
- budget exhaustion
- bookmark failure mid-batch
- transient EvtNext error
Regression tests:
- test_pull_events_preserves_setevent_during_drain: installs DRAIN_STEP_HOOK to
fire SetEvent mid-drain and asserts wait_for_events_blocking returns
EventsAvailable, not Timeout.
- test_speculative_pull_recovers_without_signal: manually clears the channel
signal via ResetEvent, confirms wait times out, then asserts pull_events still
returns events — proving the speculative timeout pull in mod.rs self-heals
independently of signal state.
Also: comment re-subscription break paths (ERROR_EVT_QUERY_RESULT_STALE and
INVALID_POSITION) noting the speculative pull as a safety net if the re-subbed
channel does not immediately re-signal; add serialization note to DRAIN_STEP_HOOK.
* fix(windows_event_log): add speculative timeout pull, deduplicate processing, fix error handling
Four related improvements to mod.rs:
1. Speculative pull on WaitResult::Timeout: call pull_events on every timeout
cycle as a belt-and-suspenders self-heal. EvtNext returns ERROR_NO_MORE_ITEMS
immediately on an empty channel (near-zero cost). If events are recovered a
warning is emitted. Guarantees recovery within one timeout period regardless
of the root cause of the lost wakeup.
2. Extract with_subscription_blocking helper: wraps the spawn_blocking
ownership-transfer pattern (move subscription in, run blocking fn, return
subscription + result). All three blocking calls (wait, normal pull,
speculative pull) now use this helper instead of inlining spawn_blocking.
3. Extract process_event_batch helper: the parse/emit/send_batch/finalize
sequence was duplicated verbatim between the EventsAvailable arm and the
speculative-timeout arm. Extracted into a shared free async function.
Rate limiting is applied consistently in both paths via the helper.
4. Fix error-handling asymmetry: the speculative pull Err branch previously
only logged warn! and continued, so a non-recoverable error (access denied,
channel not found) would spam warnings indefinitely. Now mirrors the
EventsAvailable path: emit WindowsEventLogQueryError, break on
non-recoverable errors, apply exponential backoff on recoverable ones.
* test(windows_event_log source): harden lost-wakeup regression tests against flakiness
Address two independent flakiness sources in the #25194 regression tests
so the suite is stable on real Windows CI runners.
test_pull_events_preserves_setevent_during_drain:
- Replaced a 1000ms blocking wait with an immediate 0ms poll after
pull_events returns, so the check measures only the reset/preserve
behavior of pull_events and is not contaminated by unrelated Windows
system events signaling the handle during a nonzero wait window.
- Keyed the DRAIN_STEP_HOOK fire-once to the subscription's own signal
handle so concurrent pull_events calls from other tests can't flip
the hook first and SetEvent the wrong handle.
test_speculative_pull_recovers_without_signal:
- Same 500ms→0ms poll change, opposite direction: real events arriving
during the wait would have re-signaled the manually-cleared handle
and flipped the expected Timeout into a real signal result.
- Seed a deterministic record via 'eventcreate' before subscription
creation so the non-empty-events assertion is independent of whatever
backlog the runner happens to have. Freshly provisioned images can
have an empty Application log, which would otherwise cause
pull_events(100) to legitimately return empty and false-fail the test.
* fix(windows_event_log): implement Sync for subscription types to satisfy Send bound on source future
EventLogSubscription and ChannelSubscription had unsafe impl Send but no
Sync impl. Since &T: Send requires T: Sync, process_event_batch holding
&EventLogSubscription across an .await made the entire source future !Send,
causing a compile error (ICE + future-not-Send) in release builds.
All mutation on these types requires &mut self; &self methods are read-only
or delegate to already-Sync types (RateLimiter). The underlying Windows
kernel handles are safe for concurrent access.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore(changelog): simplify windows_event_log fix fragment to user-focused one-liner
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(windows_event_log): prioritize shutdown signal
* fix(windows_event_log): lighten speculative timeout pulls
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>1 parent 9c617a7 commit 308d246
3 files changed
Lines changed: 546 additions & 112 deletions
File tree
- changelog.d
- src/sources/windows_event_log
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
160 | 262 | | |
161 | 263 | | |
162 | 264 | | |
| |||
281 | 383 | | |
282 | 384 | | |
283 | 385 | | |
284 | | - | |
285 | | - | |
286 | | - | |
| 386 | + | |
| 387 | + | |
287 | 388 | | |
288 | 389 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
| 390 | + | |
| 391 | + | |
296 | 392 | | |
297 | 393 | | |
298 | 394 | | |
299 | 395 | | |
300 | 396 | | |
301 | | - | |
302 | | - | |
303 | | - | |
| 397 | + | |
| 398 | + | |
304 | 399 | | |
305 | 400 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 401 | + | |
| 402 | + | |
313 | 403 | | |
314 | 404 | | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | 405 | | |
321 | 406 | | |
322 | 407 | | |
| |||
328 | 413 | | |
329 | 414 | | |
330 | 415 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
390 | 429 | | |
391 | 430 | | |
392 | 431 | | |
| |||
415 | 454 | | |
416 | 455 | | |
417 | 456 | | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | 457 | | |
423 | 458 | | |
424 | 459 | | |
| |||
448 | 483 | | |
449 | 484 | | |
450 | 485 | | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
451 | 554 | | |
452 | 555 | | |
453 | 556 | | |
| |||
0 commit comments