{
 "number": 36572,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/36572",
 "title": "ipc: hold event loop references when using it in `CapnpProtocol`",
 "author": "xyzconstant",
 "author_association": "CONTRIBUTOR",
 "created_at": "2026-10-19T01:51:26Z",
 "updated_at": "2026-10-29T19:00:38Z",
 "description_hash": "dd5f21f988f1fedd",
 "age_days": 13,
 "draft": false,
 "labels": [
  "Needs rebase"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "dcae5435245ec01c49cc81f1eeec438476752e3d",
 "head_ref": "2026-10-16-fix-capnp-protocol-races",
 "head_repo": "xyzconstant/bitcoin",
 "head_history": [],
 "additions": 68,
 "deletions": 23,
 "changed_files": 1,
 "commit_count": 1,
 "size_bucket": "S",
 "mergeable_state": "dirty",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {},
   "conflicts": []
  }
 },
 "acks_parsed": {
  "Hamza1610": {
   "kind": "ack",
   "hash": "dcae5435245ec01c49cc81f1eeec438476752e3d",
   "t": "2026-10-20T16:27:18Z",
   "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": [
   "Hamza1610",
   "Husteem"
  ]
 },
 "signals": {
  "needs_rebase": true,
  "ci_failed": false,
  "mergeable_state": "dirty",
  "last_author_activity": "2026-10-19T00:54:51Z",
  "last_reviewer_activity": "2026-10-20T16:27:18Z",
  "last_reviewer": "Hamza1610",
  "author_silent_days": 14,
  "waiting_on_author_days": 12,
  "days_since_update": 3
 },
 "refs": {
  "mentioned": [],
  "depends_on": [],
  "fixes": [],
  "linked_issues": [],
  "references": [],
  "conflicts": []
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [
  "src/ipc/capnp/protocol.cpp"
 ],
 "body": "`EventLoop::loop()` exits when its reference count reaches zero. In `serve()` mode, the parent connection is the only reference keeping the loop running. Other `CapnpProtocol` methods called from threads not handling parent IPC requests do not hold their own references and therefore depend on the parent connection remaining alive.\n\nAdd `loopRef()` (code suggested by @ryanofsky in https://github.com/bitcoin-core/libmultiprocess/pull/376#discussion_r4268952676), which returns a new reference to the event loop or throws if the loop is not running or is shutting down, and use it in the methods that need the loop. Protect `m_loop` with a new `m_loop_mutex` to prevent `serve()` from destroying the loop while `loopRef()` is accessing it.",
 "commits": [
  {
   "sha": "dcae5435245ec01c49cc81f1eeec438476752e3d",
   "date": "2026-10-19T00:54:51Z",
   "message": "ipc: hold event loop references when using it in CapnpProtocol\n\nEventLoop::loop() exits when its reference count reaches zero. In serve()\nmode, the parent connection is the only reference keeping the loop running.\nOther CapnpProtocol methods called from threads not handling parent IPC\nrequests do not hold their own references and therefore depend on the\nparent connection remaining alive.\n\nAdd loopRef(), which returns a new reference to the event loop or throws\nif the loop is not running or is shutting down, and use it in the methods\nthat need the loop. Protect m_loop with a new m_loop_mutex to prevent\nserve() from destroying the loop while loopRef() is accessing it.\n\nCo-authored-by: Ryan Ofsky <ryan@ofsky.org>"
  }
 ],
 "timeline": [
  {
   "t": "2026-10-20T13:34:01Z",
   "kind": "review_comment",
   "who": "Husteem",
   "assoc": "NONE",
   "path": "src/ipc/capnp/protocol.cpp",
   "commit": "dcae5435245ec01c49cc81f1eeec438476752e3d",
   "in_reply_to": null,
   "text": "A tiny Nit: redundant trailing semicolon.",
   "id": "rc:4325558344",
   "url": "https://github.com/bitcoin/bitcoin/pull/36572#discussion_r4325558344",
   "hash": "c64c0dd2751f46e2",
   "edited": "2026-10-20T13:34:30Z"
  },
  {
   "t": "2026-10-20T16:27:18Z",
   "kind": "comment",
   "who": "Hamza1610",
   "assoc": "NONE",
   "text": "Tested Ack dcae5435245ec01c49cc81f1eeec438476752e3d\nI tested the changes using  `./build/bin/test_bitcoin -t ipc_tests` and confirm, no error is detected",
   "id": "c:6295785773",
   "url": "https://github.com/bitcoin/bitcoin/pull/36572#issuecomment-6295785773",
   "hash": "7c670800ba6fd0f4",
   "edited": "2026-10-20T16:28:00Z"
  }
 ],
 "labels_log": [
  {
   "t": "2026-10-29T19:00:37Z",
   "action": "labeled",
   "label": "Needs rebase",
   "who": "DrahtBot"
  }
 ],
 "state_log": [],
 "text_chars": 1720,
 "text_tokens_estimate": 430,
 "changed_paths": [
  "src/ipc/capnp/protocol.cpp"
 ],
 "files": [
  {
   "path": "src/ipc/capnp/protocol.cpp",
   "add": 68,
   "del": 23
  }
 ],
 "test_lines": 0,
 "git": {
  "head": "dcae5435245ec01c49cc81f1eeec438476752e3d",
  "head_matches_backup": true,
  "base": "924f4c4ac78b0cd3b917c694f42c0651a6f3003a",
  "patch_id": "cbf785299cf8c8f4",
  "commits": [
   {
    "sha": "dcae543524",
    "subject": "ipc: hold event loop references when using it in CapnpProtocol",
    "files": 1,
    "add": 68,
    "del": 23
   }
  ],
  "patch_truncated": false
 },
 "patch_id": "cbf785299cf8c8f4",
 "input_hash": "9d811ae40dcafcea",
 "extracted_at": "2026-11-02T01:09:49+00:00"
}