Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(p2p): Avoid inifinty loop during transport/listener Accept #3662

Merged
merged 12 commits into from
Feb 5, 2025

Conversation

gfanton
Copy link
Member

@gfanton gfanton commented Feb 2, 2025

This PR aims to fix two potential infinite loops during Accept in the p2p package.

  • First, it removes the ErrTransportInactive error. Based on how Accept is used, I believe the inactive error does not make much sense here. Accept should always block, even in an inactive state. Having Accept in two states—blocking and non-blocking—complicates the logic unnecessarily. Additionally, returning an inactive error creates an infinite loop, as the handler will keep looping over Accept until a blocking state is reached.

  • If the underlying transport or listener is closed, the context should also be canceled, as this is not a recoverable error. Currently, if the transport or listener is closed, it will loop indefinitely until the context is properly closed. While this situation should rarely occur, since the context should be canceled when closing the transport, I believe it is safe to force the cancellation of the context to avoid any potential deadloop.

EDIT: I've removed the context select from the loop to simplify the logic. The logic remains unchanged, but it avoids having two sources of truth.

This PR also reduces unnecessary error and warning noise when the listener or transport is closed.

@gfanton gfanton requested a review from zivkovicmilos February 2, 2025 11:25
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Feb 2, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Feb 2, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: gfanton/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

Attention: Patch coverage is 85.91549% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tm2/pkg/p2p/transport.go 81.57% 7 Missing ⚠️
tm2/pkg/p2p/switch.go 90.62% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@gfanton gfanton force-pushed the fix/p2p/errors-handling branch from 5e75bbc to 51b2d7f Compare February 2, 2025 11:36
tm2/pkg/p2p/switch.go Outdated Show resolved Hide resolved
tm2/pkg/p2p/transport.go Outdated Show resolved Hide resolved
@gfanton gfanton requested a review from moul February 2, 2025 17:23
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Looks sound 💯

Thank you for the fixup 🙏

tm2/pkg/p2p/transport.go Show resolved Hide resolved
tm2/pkg/p2p/transport.go Outdated Show resolved Hide resolved
tm2/pkg/p2p/transport.go Show resolved Hide resolved
tm2/pkg/p2p/switch_test.go Outdated Show resolved Hide resolved
@gfanton gfanton merged commit 9e6a67b into gnolang:master Feb 5, 2025
62 checks passed
@gfanton gfanton deleted the fix/p2p/errors-handling branch February 5, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Development

Successfully merging this pull request may close these issues.

4 participants