Commit 2abf44d
authored
fix: deadlock in main loop (#696)
Fixes an issue I made in #692. Like all concurrency bugs, this one is
insidious.
At a glance combining `next_event` with `handle_next_invocation` makes a
lot of sense. I wish I could blame it on an LLM, but I had the bright
idea this morning as I reviewed the code.
In the flush_at_end and start cases, it works totally fine.
The problem is that in the high-throughput case where we switch to
periodic mode, we had a tokio::select! block polling over multiple
futures.
In #692 with the combined next_event and handle_next_invocation method,
we end up polling over a future which both waited for the response from
/next_event but then immediately blocked until it could lock the
invocation processor and insert the new request.
Unfortunately this caused a deadlock because inside the tokio::select!
block, we also lock the invocation processor when we need to handle some
event bus events.
If the response from next_event returns and tokio enters that branch, it
may not return if it can't get the lock. But if a request task is
inserting data into the invocation processor, we can deadlock and never
poll that branch again.

1 parent a3d3b1f commit 2abf44d
1 file changed
+7
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| 498 | + | |
498 | 499 | | |
499 | 500 | | |
500 | 501 | | |
501 | | - | |
| 502 | + | |
502 | 503 | | |
503 | 504 | | |
504 | 505 | | |
| |||
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
| 545 | + | |
544 | 546 | | |
545 | | - | |
| 547 | + | |
546 | 548 | | |
547 | 549 | | |
548 | 550 | | |
| |||
592 | 594 | | |
593 | 595 | | |
594 | 596 | | |
595 | | - | |
596 | | - | |
| 597 | + | |
597 | 598 | | |
598 | 599 | | |
599 | 600 | | |
| |||
607 | 608 | | |
608 | 609 | | |
609 | 610 | | |
610 | | - | |
| 611 | + | |
611 | 612 | | |
612 | 613 | | |
613 | 614 | | |
| |||
766 | 767 | | |
767 | 768 | | |
768 | 769 | | |
769 | | - | |
770 | | - | |
| 770 | + | |
771 | 771 | | |
772 | 772 | | |
773 | | - | |
774 | 773 | | |
775 | 774 | | |
776 | 775 | | |
| |||
0 commit comments