{
 "number": 36617,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/36617",
 "title": "test: Fix intermittent issue in p2p_orphan_handling.py",
 "author": "maflcko",
 "author_association": "MEMBER",
 "created_at": "2026-10-22T21:08:08Z",
 "updated_at": "2026-10-23T15:52:02Z",
 "description_hash": "52ba628ee85db3bb",
 "age_days": 10,
 "draft": false,
 "labels": [
  "Tests"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "faf819bf23e8752644695e332cc00413d94af938",
 "head_ref": "2610-test-fix-int-orphan",
 "head_repo": "maflcko/bitcoin-core",
 "head_history": [],
 "additions": 2,
 "deletions": 2,
 "changed_files": 1,
 "commit_count": 1,
 "size_bucket": "S",
 "mergeable_state": "clean",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {
    "ack": [
     {
      "login": "Conradgabe",
      "url": "https://github.com/bitcoin/bitcoin/pull/36617#issuecomment-6366524818"
     }
    ]
   },
   "conflicts": []
  }
 },
 "acks_parsed": {
  "Conradgabe": {
   "kind": "ack",
   "hash": "faf819bf23e8752644695e332cc00413d94af938",
   "t": "2026-10-23T13:54:16Z",
   "stale": false
  }
 },
 "acks_tally": {
  "ack": 1,
  "stale_ack": 0,
  "concept_ack": 0,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": [
   "Conradgabe"
  ]
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": false,
  "mergeable_state": "clean",
  "last_author_activity": "2026-10-23T15:52:02Z",
  "last_reviewer_activity": "2026-10-23T15:48:19Z",
  "last_reviewer": "Conradgabe",
  "author_silent_days": 9,
  "waiting_on_author_days": 0,
  "days_since_update": 9
 },
 "refs": {
  "mentioned": [],
  "depends_on": [],
  "fixes": [],
  "linked_issues": [],
  "references": [],
  "conflicts": []
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [],
 "body": "Turns out https://github.com/bitcoin/bitcoin/pull/32092 was incomplete and the issue can still happen:\n\nhttps://github.com/bitcoin/bitcoin/actions/runs/39809026827/job/119929911875#step:14:14454\n\nThe basic idea is that peer1 disconnects to clear its orphan state. This happens in `DisconnectNodes`->`DeleteNode`->`FinalizeNode`->`TxDownloadManager::DisconnectedPeer`.\n\nIn my prior fix, I assumed that `DisconnectNodes` in the `net` thread would be possible to sync on via a ping-pong. However, the msghand thread may hold a reference to the node, preventing deletion and only moving the node to `m_nodes_disconnected`. Afterward, the `net` thread may hand the pings to the `msghand` thread and go to sleep for a bit.\n\nThus, the test proceed and cause a split `getdata`, meaning that `peer2.wait_for_parent_requests([int(parent_peekaboo_AB[\"txid\"], 16), int(parent_missing[\"txid\"], 16)])` fails.\n\nFix this by just waiting for `TxDownloadManager::DisconnectedPeer` to have happened via `self.wait_until(lambda: len(node.getorphantxs(verbosity=2)[0][\"from\"]) == 1)`.\n\nEdit: Possible diff to reproduce with ~10% failure rate:\n\n```diff\ndiff --git a/src/net.cpp b/src/net.cpp\nindex 1201d3bcb4..e81623484b 100644\n--- a/src/net.cpp\n+++ b/src/net.cpp\n@@ -2229,2 +2229,3 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,\n                     WakeMessageHandler();\n+            UninterruptibleSleep(333ms *m_nodes_disconnected.size());\n                 }\n@@ -3261,2 +3262,3 @@ void CConnman::ThreadMessageHandler()\n             }\n+            UninterruptibleSleep(33ms);\n         }\n```\n\nCmd: `./bld-cmake/test/functional/test_runner.py $(for i in {1..20}; do echo -n \"p2p_orphan_handling.py \";done) -j $( nproc )`",
 "commits": [
  {
   "sha": "faf819bf23e8752644695e332cc00413d94af938",
   "date": "2026-10-22T20:20:55Z",
   "message": "test: Fix intermittent issue in p2p_orphan_handling.py"
  }
 ],
 "timeline": [
  {
   "t": "2026-10-23T13:54:16Z",
   "kind": "comment",
   "who": "Conradgabe",
   "assoc": "NONE",
   "text": "crACK faf819bf23e8752644695e332cc00413d94af938\n\nnit: the comment on `peer2.sync_with_ping()` (\"Sync with the 'net' thread which completes the disconnection fully\") is no longer correct given this PR update, since the ping doesn't guarantee peer1's deferred deletion has happened. The comment could be changed to something like \"Sync with the 'net' thread and confirm peer2's messages have been processed\".\n\nhttps://github.com/bitcoin/bitcoin/blob/faf819bf23e8752644695e332cc00413d94af938/test/functional/p2p_orphan_handling.py#L829",
   "id": "c:6366524818",
   "url": "https://github.com/bitcoin/bitcoin/pull/36617#issuecomment-6366524818",
   "hash": "cbcb14471b32b8a3",
   "edited": null
  },
  {
   "t": "2026-10-23T14:05:38Z",
   "kind": "comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "text": "[quoted text omitted]\n\nCan you please leave code review threads in the code tab. Otherwise, it is hard to follow the threads. Also, this comment doesn't seem right? `self.wait_until(lambda: len(node.getorphantxs(verbosity=2)[0][\"from\"]) == 1)` establishes that `DisconnectedPeer` has been (or is being) called. Thus, the next ping will ensure the disconnect is fully handled and the code and comment is correct?",
   "id": "c:6366757422",
   "url": "https://github.com/bitcoin/bitcoin/pull/36617#issuecomment-6366757422",
   "hash": "5a1e1cc848a344df",
   "edited": null
  },
  {
   "t": "2026-10-23T15:48:19Z",
   "kind": "comment",
   "who": "Conradgabe",
   "assoc": "NONE",
   "text": "[quoted text omitted]\n\nSure, I\u2019ll leave code review threads in the Code tab going forward. On the nit, I interpreted the comment as referring to `sync_with_ping()` synchronizing with the net thread after `DisconnectedPeer` has been invoked, rather than implying that the ping itself guarantees that the deferred deletion has already happened. Since the preceding `wait_until(...)` establishes that `DisconnectedPeer` has been called, the subsequent ping does ensure that the disconnect is fully handled, so I think the existing comment is still accurate.",
   "id": "c:6368859313",
   "url": "https://github.com/bitcoin/bitcoin/pull/36617#issuecomment-6368859313",
   "hash": "dd491890ea99594a",
   "edited": "2026-10-23T15:51:22Z"
  },
  {
   "t": "2026-10-23T15:52:02Z",
   "kind": "comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "text": "Also when writing comments in discussions, you can not use LLMs, per https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md",
   "id": "c:6368936261",
   "url": "https://github.com/bitcoin/bitcoin/pull/36617#issuecomment-6368936261",
   "hash": "42d6958f769da3d0",
   "edited": null
  }
 ],
 "labels_log": [
  {
   "t": "2026-10-22T21:08:13Z",
   "action": "labeled",
   "label": "Tests",
   "who": "DrahtBot"
  }
 ],
 "state_log": [],
 "text_chars": 3468,
 "text_tokens_estimate": 867,
 "changed_paths": [
  "test/functional/p2p_orphan_handling.py"
 ],
 "files": [
  {
   "path": "test/functional/p2p_orphan_handling.py",
   "add": 2,
   "del": 2
  }
 ],
 "test_lines": 4,
 "git": {
  "head": "faf819bf23e8752644695e332cc00413d94af938",
  "head_matches_backup": true,
  "base": "152a55397e451fed9c10041bddf01aa6839847d5",
  "patch_id": "a7d345acd086ca9e",
  "commits": [
   {
    "sha": "faf819bf23",
    "subject": "test: Fix intermittent issue in p2p_orphan_handling.py",
    "files": 1,
    "add": 2,
    "del": 2
   }
  ],
  "patch_truncated": false
 },
 "patch_id": "a7d345acd086ca9e",
 "input_hash": "f5a51d3363dcc0c0",
 "extracted_at": "2026-11-02T01:09:49+00:00"
}