Commit 572e586
Backport TestResubscribeWithCompletedSubscription and deadlock fix to release/3.3 (#18862)
Backports test case and deadlock fix from PR #18562 (commit
`f3e42e7626`) that validates `Unsubscribe()` doesn't deadlock when the
subscription producer exits before unsubscription.
## Changes
- **Test case**: `TestResubscribeWithCompletedSubscription` in
`p2p/event/subscription_test.go`
- Validates no deadlock when producer completes before `Unsubscribe()`
is called
- **Deadlock fix**: Make `resubscribeSub.unsub` channel buffered (size
1)
- Without buffer, `Unsubscribe()` blocks when sending after resubscribe
loop exits
- Buffer allows send to complete even when no receiver is present
```go
// Before: unbuffered channel causes deadlock
unsub: make(chan struct{})
// After: buffered channel prevents deadlock
unsub: make(chan struct{}, 1)
```
The test reproduces the deadlock scenario by ensuring the subscription
completes successfully before calling `Unsubscribe()`.
## Original Source
- **Original PR**: #18562 - "Sync p2p/event with geth's event"
- **Original Commit**: f3e42e7
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
> Backport the test case `TestResubscribeWithCompletedSubscription` from
the `main` branch of Erigon to the branch `release/3.3`. This test
validates that the `Unsubscribe` method does not result in a deadlock
when the producer exits first. Reference implementation in
`p2p/event/subscription_test.go` from commit
`b8d1242103d81d46591cf86c71d8e182bc8c2add`. Ensure it only modifies the
`release/3.3` branch and includes the additional test case.
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
*This pull request was created from Copilot chat.*
>
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/erigontech/erigon/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: anacrolix <988750+anacrolix@users.noreply.github.com>1 parent d176276 commit 572e586
2 files changed
+25
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
0 commit comments