Commit 9c72ef4
committed
Fix deadlock with many peers, few threads, and slow postgres writes
When we have many peers but relatively few threads, and postgres
writes fall behind enough to block the async stream of gossip, we
can end up deadlocking on the `PeerManager` `peers` thread.
Specifically, because `PeerManager::process_events` holds a
`peers` (read) lock while fetching messages (during which time we
`block_in_place` trying to push gossip to the async stream), any
other tasks which try to touch the `peers` lock in write mode (e.g.
connecting to a peer or processing a disconnection) we'll hang
until some postgres writes finish. If we get enough threads
blocked, we end up blocking the tokio reactor and the postgres
writes will stall, fully deadlocking.
There's not a great solution to this, instead we just have to
ensure we have enough threads which we enforce.1 parent 010011a commit 9c72ef4
3 files changed
Lines changed: 25 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
9 | 28 | | |
0 commit comments