Skip to content

Backport TestResubscribeWithCompletedSubscription and deadlock fix to release/3.3#18862

Merged
anacrolix merged 2 commits intorelease/3.3from
copilot/backport-test-resubscribe-case
Jan 30, 2026
Merged

Backport TestResubscribeWithCompletedSubscription and deadlock fix to release/3.3#18862
anacrolix merged 2 commits intorelease/3.3from
copilot/backport-test-resubscribe-case

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

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
// 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 prompt

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.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: anacrolix <988750+anacrolix@users.noreply.github.com>
Copilot AI changed the title [WIP] Backport test case for resubscribing without deadlock Backport TestResubscribeWithCompletedSubscription and deadlock fix to release/3.3 Jan 29, 2026
Copilot AI requested a review from anacrolix January 29, 2026 13:00
@anacrolix
Copy link
Contributor

@copilot link to the original PR and commits on main

Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

@copilot link to the original PR and commits on main

Original PR: #18562
Original commit on main: f3e42e7

This backport includes both the test case and the deadlock fix from that PR.

@anacrolix
Copy link
Contributor

@copilot what happened to the other changes in the commit from main? why weren't those brought over?

Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

@copilot what happened to the other changes in the commit from main? why weren't those brought over?

The original task requested backporting only the test case TestResubscribeWithCompletedSubscription. I included the deadlock fix in subscription.go because it's required for the test to pass.

The other changes from PR #18562 were in feed.go and feed_test.go. These appear to be refactoring changes that are independent of the deadlock fix. Should I include those changes as well?

@anacrolix
Copy link
Contributor

@copilot do they affect correctness in other regard?

@anacrolix anacrolix marked this pull request as ready for review January 30, 2026 01:44
Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

@copilot do they affect correctness in other regard?

Yes, the feed.go changes fix a potential race condition in type initialization. Currently, f.etype can be set under the f.mu lock in typecheck(), which creates timing issues between concurrent Subscribe/Send calls.

PR #18562 fixes this by:

  1. Using sync.Once to atomically initialize the type on first Subscribe/Send
  2. Moving type checks outside the mutex lock (after initialization via Once)
  3. Removing the separate typecheck() function

The feed_test.go changes are just for compatibility (TypeFor vs TypeOf).

Should I include all the feed.go and feed_test.go changes from PR #18562?

Copy link
Contributor

@anacrolix anacrolix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked the change fixes the test, and the other changes from the original PR for main aren't required.

@anacrolix anacrolix enabled auto-merge (squash) January 30, 2026 01:51
@anacrolix anacrolix merged commit 572e586 into release/3.3 Jan 30, 2026
17 of 22 checks passed
@anacrolix anacrolix deleted the copilot/backport-test-resubscribe-case branch January 30, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants