Conversation
|
@acul71 @yashksaini-coder @sumanjeet0012 Hey everyone, I've just pushed a fix for the "Task destroyed but pending" warnings we were seeing in the tests. I implemented proper Everything is passing locally with no warnings now. PR is up. |
6a5f959 to
1b27fe3
Compare
|
Hello @Smartdevs17 thanks for this PR. Full review here: AI Pull Request Review: #1208 — feat: enhance BasicHost shutdownPR: libp2p/py-libp2p#1208 1. Summary of ChangesThis PR enhances BasicHost shutdown to fix "Task was destroyed but it is pending!" warnings in tests by ensuring proper resource cleanup in Host and Network components. What changed:
Files touched:
Note: The PR description mentions ensuring Breaking changes / deprecations: None. This adds and uses existing 2. Branch Sync Status and Merge ConflictsBranch Sync Status
Merge Conflict Analysis
3. Strengths
4. Issues FoundCritical
Major
Minor
5. Security Review
6. Documentation and Examples
7. Newsfragment RequirementStatus: ❌ BLOCKER — missing newsfragment and optional issue link
8. Tests and ValidationIntent: The PR adds explicit host cleanup in one test and in Local verification (with project venv activated):
Conclusion: With the project virtual environment activated, the test suite and documentation build complete successfully. Lint and typecheck were not run successfully (pre-commit missing in this environment). The code changes are validated by the passing test run. 9. Recommendations for Improvement
10. Questions for the Author
11. Overall Assessment
Review generated using the py-libp2p AI Pull Request Review Prompt. Review context: PR branch checked out, branch sync and merge conflict check performed, issue #92 and PR description/comments read. Tests and docs run with project venv activated (make test: 2164 passed, 16 skipped; make linux-docs: build and doctests passed). Lint and typecheck failed in this environment (pre-commit not found). |
What was wrong?
Tests were failing with "Task was destroyed but it is pending!" warnings due to lack of proper resource cleanup in
HostandNetworkcomponents. Existing implementations ofBasicHostandSwarmdid not fully handle the shutdown of background tasks and services (like mDNS, Identify) during teardown.Issue #92
How was it fixed?
Implemented explicit
async def close()methods forBasicHostandSwarm(Network).BasicHost: Added cleanup logic to stop background services (mDNS,bootstrap,UPnP), cancel all pendingidentifytasks usingtrio.CancelScope, and close the underlying network.Swarm: Ensuredclose()method satisfies theINetworkServiceinterface and properly cleans up connections and listeners.HostFactoryto automatically callclose()on hosts during teardown, resolving cleanup issues in all tests using these factories. Added explicit cleanup totest_basic_host.py.To-Do