Commit 69440fe
fix(audience): guard SendBatch against overlapping timer ticks
System.Threading.Timer does not serialise callbacks — with a 5s flush
interval and HTTP requests that can run up to the 30s timeout, a slow
network stacks six overlapping callbacks, each on its own ThreadPool
thread blocked inside SendBatchAsync.
Gate SendBatch with Interlocked.CompareExchange so subsequent ticks
return in microseconds while a send is in flight. The guard is cleared
in finally so a throw inside GetResult or RescheduleSendTimer still
releases the next tick, and defensively in Shutdown so a WaitOne that
times out on a still-running callback cannot strand the flag at 1
across an Init/Shutdown cycle.
Exposes SendBatch via an internal testing hook so the guard can be
exercised without a real timer; the new test blocks the HTTP handler,
fires an overlapping tick, and asserts only one request reaches the
wire.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent f1d6685 commit 69440fe
2 files changed
Lines changed: 93 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
29 | 36 | | |
30 | 37 | | |
31 | 38 | | |
| |||
484 | 491 | | |
485 | 492 | | |
486 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
487 | 500 | | |
488 | 501 | | |
489 | 502 | | |
| |||
553 | 566 | | |
554 | 567 | | |
555 | 568 | | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
556 | 573 | | |
557 | 574 | | |
558 | 575 | | |
| |||
578 | 595 | | |
579 | 596 | | |
580 | 597 | | |
581 | | - | |
582 | | - | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
583 | 603 | | |
584 | | - | |
| 604 | + | |
585 | 605 | | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
591 | 610 | | |
592 | | - | |
593 | | - | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
594 | 620 | | |
595 | | - | |
596 | 621 | | |
597 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
598 | 628 | | |
599 | 629 | | |
600 | 630 | | |
| |||
Lines changed: 51 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
853 | 904 | | |
854 | 905 | | |
0 commit comments