cln/wire
daywalker90 c95bc8712e wire_sync: tolerate a non-blocking fd when reading/writing a message
On macOS under load, subdaemons intermittently die:

  connectd: **BROKEN** STATUS_FAIL_HSM_IO: No hsmd ECDH response
  channeld: exits 0 after WIRE_HSMD_GET_PER_COMMITMENT_POINT

Both are a synchronous wire_sync_read() returning NULL on a fresh
connection.  The HSM fd in a subdaemon is one end of a socketpair created
by hsmd (whose io loop sets O_NONBLOCK on the other end) and passed
hsmd -> lightningd -> subdaemon via SCM_RIGHTS.  On macOS the O_NONBLOCK
flag follows the shared open file description across that chain, so the
subdaemon's fd can be non-blocking, and read()/write() return EAGAIN
before hsmd's (fast) reply has landed.  Linux keeps the descriptions
independent, which is why this never reproduces there.

The previous attempts to force the fd blocking from the subdaemon
(io_fd_block in ecdh_hsmd_setup) cannot win, because hsmd owns the other
end of the same open file description and keeps it non-blocking.

Fix at the shared choke point instead: make wire_sync_read() and
wire_sync_write() tolerant of O_NONBLOCK by polling on EAGAIN and
resuming, preserving any partial read.  "Sync" then really means "read or
write a complete message", regardless of the fd's blocking state.  This
covers connectd's ecdh(), channeld's hsm_req(), and every other subdaemon
that does synchronous HSM I/O (openingd, closingd, onchaind).

Also drop the now-unneeded io_fd_block() toggling from ecdh_hsmd_setup(),
and include errno in the HSM I/O failure messages so a recurrence is
diagnosable from the daemon log.

Changelog-Fixed: connectd: fix intermittent "No hsmd ECDH response" crash on macOS under load (issue #9060).
2026-08-12 12:43:05 +02:00
..
test common: add randbytes() wrapper to override cryptographic entropy: $CLN_DEV_ENTROPY_SEED 2026-07-13 18:15:06 -07:00
bolt12_wire.csv bolt12: import draft payer proof spec. 2026-05-11 11:13:55 +09:30
channel_type_wire.csv common/channel_type: wrapper for generated 'struct channel_type'. 2021-09-13 15:53:23 +02:00
extracted_bolt12_01_recurrence.patch wire: update to slight spec neating. 2025-10-01 15:31:30 +09:30
extracted_bolt12_02_payer_proofs.patch bolt12: import draft payer proof spec. 2026-05-11 11:13:55 +09:30
extracted_onion_03_onionmsg-payload-as-bytearr.patch wire: update to bolt version which has offers included. 2025-02-11 20:19:01 -06:00
extracted_onion_05_remove-onion_message.patch BOLTs: update which renames blinding terminology. 2024-10-16 07:14:32 +10:30
extracted_peer-shutdown-wrong_funding.patch BOLTs: more textual changes. 2026-04-30 20:09:31 +09:30
extracted_peer_04_opt_will_fund.patch BOLT catchup: quiescence is included. 2024-10-16 07:14:32 +10:30
extracted_peer_05_newonion.patch BOLTs: update which renames blinding terminology. 2024-10-16 07:14:32 +10:30
extracted_peer_cln_batch_element.patch wire/splice: rename messages and TLV fields per updated BOLTs 2026-06-19 09:38:06 +09:30
fromwire.c wire: add explicit-length fromwire_peektype variant. 2025-11-28 09:16:53 +10:30
Makefile common: routines to create and validate payer proofs. 2026-05-11 11:13:55 +09:30
onion_defs.h global: remove unnecessary includes from headers. 2025-10-23 06:44:04 +10:30
onion_wire.csv wire: update to bolt version which has offers included. 2025-02-11 20:19:01 -06:00
peer_wire.c wire/splice: rename messages and TLV fields per updated BOLTs 2026-06-19 09:38:06 +09:30
peer_wire.csv wire/splice: rename messages and TLV fields per updated BOLTs 2026-06-19 09:38:06 +09:30
peer_wire.h global: remove unnecessary includes from headers. 2025-10-23 06:44:04 +10:30
tlvstream.c global: more missing BOLT quotes. 2026-04-30 12:17:43 +09:30
tlvstream.h global: remove unnecessary includes from headers. 2025-10-23 06:44:04 +10:30
towire.c global: remove unnecessary includes from C files. 2025-10-23 06:44:04 +10:30
wire.h wire: add explicit-length fromwire_peektype variant. 2025-11-28 09:16:53 +10:30
wire_io.c global: remove unnecessary includes from C files. 2025-10-23 06:44:04 +10:30
wire_io.h connectd: do decryption for peers. 2022-01-20 15:24:06 +10:30
wire_sync.c wire_sync: tolerate a non-blocking fd when reading/writing a message 2026-08-12 12:43:05 +02:00
wire_sync.h wire_sync_write: support take() 2017-06-27 10:25:53 +09:30