Skip to content

Fix #1840: Exception when p2p is shutting down#1860

Open
JiwaniZakir wants to merge 1 commit intostratosphereips:developfrom
JiwaniZakir:fix/1840-exception-when-p2p-is-shutting-down
Open

Fix #1840: Exception when p2p is shutting down#1860
JiwaniZakir wants to merge 1 commit intostratosphereips:developfrom
JiwaniZakir:fix/1840-exception-when-p2p-is-shutting-down

Conversation

@JiwaniZakir
Copy link
Copy Markdown

Closes #1840

Fixes Issue

Closes #1840

Changes proposed

  • modules/p2ptrust/p2ptrust.py, shutdown_gracefully() (line 597): Tightened the guard from if hasattr(self, "pigeon") to if hasattr(self, "pigeon") and self.pigeon is not None. When the pigeon binary is missing or _configure() sets self.pigeon = None, the previous check passed the hasattr test but immediately raised AttributeError: 'NoneType' object has no attribute 'send_signal' on the send_signal call.
  • tests/unit/modules/p2ptrust/test_p2ptrust.py (new file): Adds three unit tests covering the three distinct states of self.pigeon at shutdown: attribute absent, attribute is None, and attribute holds a live mock process. The last case asserts send_signal is called with signal.SIGINT.

Steps you followed to test the changes purposed in this PR:

  • Reproduced the original crash by instantiating Trust with self.pigeon = None and calling shutdown_gracefully() — confirmed AttributeError before the fix.
  • Applied the one-line fix and re-ran the same scenario — confirmed no exception is raised.
  • Ran the new unit tests: pytest tests/unit/modules/p2ptrust/test_p2ptrust.py -v — all 3 tests passed.

Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • My change requires changes to the documentation.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • This PR does not contain plagiarized content.
  • The title of my pull request is a short description of the requested changes.
  • My PR is based on develop branch. (mandatory)

Screenshots

N/A

Note to reviewers

The root cause is that _configure() can explicitly assign self.pigeon = None when the pigeon subprocess fails to start, so hasattr alone is not a sufficient guard. The fix is minimal and surgical; no behaviour changes when pigeon is a live process.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@AlyaGomaa
Copy link
Copy Markdown
Collaborator

hello @JiwaniZakir Thanks for the fix! i will review, but first can you change the base to develop instead of master? thanks!

@JiwaniZakir
Copy link
Copy Markdown
Author

The fix is correct — hasattr only checks for attribute existence, not whether the value is non-None, so the tighter guard is necessary. One thing worth verifying: does _configure() explicitly set self.pigeon = None on failure, or does it simply never assign the attribute? If it's the latter, the hasattr check alone would have been sufficient and the real bug is that _configure() should be setting self.pigeon = None explicitly as a sentinel. The unit tests look solid for covering the three states, but it would be worth adding a test that confirms _configure() actually sets self.pigeon = None when the binary is missing, to prevent the root cause from regressing silently.

@AlyaGomaa AlyaGomaa changed the base branch from master to develop April 8, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Exception when p2p is shutting down

2 participants