net, http: handle socket errors separately from reads #36963

Open
Sjors wants to merge 8 commits from 2026/11/http-socket-errors into master AGit
Sjors commented 2026-11-24 12:27:56 +00:00 (Migrated from github.com)

With poll(), which we only use on Linux, a socket error or hangup is reported whether or not we asked for it. If that happens for a peer we did not request to read from, disconnect directly. This just adds clarity: previously we would attempt a send that would then fail. The only side-effect is a changed log message. Nothing changes on other platforms: since bitcoin/bitcoin#36716 they no longer report errors for established connections.

The last commit does the same for HTTP, where on error it also no longer attempts a final read from a client whose reads are paused.

As a followup to bitcoin/bitcoin#36716, p2p_socket_errors.py adds coverage for existing behavior:

  • the node ignores a single urgent byte: the connection stays open, ordinary data is still processed and the urgent byte is not counted as received.
  • a peer resets the connection while the node's send to it is stalled and receiving from it is paused: the node disconnects without reading anything more (the change above only changes the log message)

Similarly interface_http.py checks that:

  • a single urgent byte does not disturb an ordinary request.
  • a client reset while the server has unsent responses (the HTTP change only changes the log message)

The first two commits follow up on review comments in bitcoin/bitcoin#36716: the ErrorEvent documentation now describes the behavior by poll() and select() rather than by platform, as suggested in https://github.com/bitcoin/bitcoin/pull/36716#discussion_r4745459504, and a comment is dropped from the wait_ignores_urgent_data unit test, as suggested in https://github.com/bitcoin/bitcoin/pull/36716#discussion_r4700726004.

To support the new tests, the test framework gains:

  • wait_for_send_stall(), moved out of p2p_ping_ibd.py
  • a reset option for peer_disconnect(), which closes the connection with a TCP reset
  • mine_large_block() returns the block hash and size
  • pack_linger(), and linux_host / windows_target to tell which log message to expect
With `poll()`, which we only use on Linux, a socket error or hangup is reported whether or not we asked for it. If that happens for a peer we did not request to read from, disconnect directly. This just adds clarity: previously we would attempt a send that would then fail. The only side-effect is a changed log message. Nothing changes on other platforms: since bitcoin/bitcoin#36716 they no longer report errors for established connections. The last commit does the same for HTTP, where on error it also no longer attempts a final read from a client whose reads are paused. As a followup to bitcoin/bitcoin#36716, `p2p_socket_errors.py` adds coverage for existing behavior: - the node ignores a single urgent byte: the connection stays open, ordinary data is still processed and the urgent byte is not counted as received. - a peer resets the connection while the node's send to it is stalled and receiving from it is paused: the node disconnects without reading anything more (the change above only changes the log message) Similarly `interface_http.py` checks that: - a single urgent byte does not disturb an ordinary request. - a client reset while the server has unsent responses (the HTTP change only changes the log message) The first two commits follow up on review comments in bitcoin/bitcoin#36716: the `ErrorEvent` documentation now describes the behavior by `poll()` and `select()` rather than by platform, as suggested in https://github.com/bitcoin/bitcoin/pull/36716#discussion_r4745459504, and a comment is dropped from the `wait_ignores_urgent_data` unit test, as suggested in https://github.com/bitcoin/bitcoin/pull/36716#discussion_r4700726004. To support the new tests, the test framework gains: - `wait_for_send_stall()`, moved out of `p2p_ping_ibd.py` - a `reset` option for `peer_disconnect()`, which closes the connection with a TCP reset - `mine_large_block()` returns the block hash and size - `pack_linger()`, and `linux_host` / `windows_target` to tell which log message to expect
DrahtBot commented 2026-11-24 12:28:05 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK jeanpablojp

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36434 (http: support unix sockets by pinheadmz)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36963 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36963.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36963#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36963#pullrequestreview-6155947749) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36434](https://github.com/bitcoin/bitcoin/pull/36434) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36434.svg"></sub> (http: support unix sockets by pinheadmz) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.

🟠 Minor · Ping-batch wait depends on recv() boundaries

Although no failing environment was identified, a short read of the ping batch can trigger backpressure early and make this functional test time out before the reset.

Location: test/functional/p2p_socket_errors.py:105 (head).

🔵 Suggestion · HTTP reset test does not verify client removal

The HTTP reset check asserts no server-side outcome on select() targets and only a pre-disconnection log on poll() targets, so it can miss a client-removal regression.

Location: test/functional/interface_http.py:920 (head).


Reviewed: 4a9e07cd6129 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:fe1c21a54fafe6fb93537e8286cb49a09ac104e2 --> <!-- ralph-head:4a9e07cd61294be4c36781e1891d6c37b4c9f8ae --> <!-- ralph-case:c17a52fa6106d282a2b5ae405bb429099377b3a032bef5e0e954cdadde406982 --> Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments. **🟠 Minor · Ping-batch wait depends on `recv()` boundaries** Although no failing environment was identified, a short read of the ping batch can trigger backpressure early and make this functional test time out before the reset. Location: [`test/functional/p2p_socket_errors.py:105`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/4a9e07cd61294be4c36781e1891d6c37b4c9f8ae/test/functional/p2p_socket_errors.py#L105>) (head). **🔵 Suggestion · HTTP reset test does not verify client removal** The HTTP reset check asserts no server-side outcome on `select()` targets and only a pre-disconnection log on `poll()` targets, so it can miss a client-removal regression. Location: [`test/functional/interface_http.py:920`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/4a9e07cd61294be4c36781e1891d6c37b4c9f8ae/test/functional/interface_http.py#L920>) (head). <!-- Review tier: sensitive --> --- Reviewed: [`4a9e07cd6129`](<https://git.fish.foo/bitcoin/bitcoin/commit/4a9e07cd61294be4c36781e1891d6c37b4c9f8ae>) · [Review report](<https://review.fish.foo/report/36963-4a9e07cd61294be4c36781e1891d6c37b4c9f8ae-3385-6.html>) · [Previous reports](<https://review.fish.foo/traces/36963/>) [permalink](<https://review.fish.foo/report/36963-4a9e07cd61294be4c36781e1891d6c37b4c9f8ae-3385-6.html>)
DrahtBot commented 2026-11-26 15:27:04 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sjors commented 2026-11-26 16:49:49 +00:00 (Migrated from github.com)

#36716 landed, rebased.

I made the check_reset_while_sending test easier to understand.

#36716 landed, rebased. I made the `check_reset_while_sending` test easier to understand.
DrahtBot commented 2026-11-27 13:07:57 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sjors commented 2026-11-27 20:47:52 +00:00 (Migrated from github.com)

Trivial rebase after #36916.

Trivial rebase after #36916.
jeanpablojp (Migrated from github.com) reviewed 2026-12-02 17:44:53 +00:00
jeanpablojp (Migrated from github.com) left a comment

tACK 4a9e07cd61

Tested on Linux and macOS.

tACK 4a9e07cd61294be4c36781e1891d6c37b4c9f8ae Tested on Linux and macOS.
jeanpablojp (Migrated from github.com) commented 2026-12-02 17:44:53 +00:00

The suggestion below fails on Linux without client->Disconnect(), and passes on Linux and macOS with it.

        port = conn.conn.sock.getsockname()[1]
        expected_msgs.append(f"Disconnecting HTTP client 127.0.0.1:{port} (")
        conn.conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, pack_linger(enabled=True, timeout=0))
        with self.node.assert_debug_log(expected_msgs, timeout=10):
The suggestion below fails on Linux without `client->Disconnect()`, and passes on Linux and macOS with it. ```suggestion port = conn.conn.sock.getsockname()[1] expected_msgs.append(f"Disconnecting HTTP client 127.0.0.1:{port} (") conn.conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, pack_linger(enabled=True, timeout=0)) with self.node.assert_debug_log(expected_msgs, timeout=10): ```
jeanpablojp (Migrated from github.com) commented 2026-12-02 17:44:53 +00:00

The test takes 42 to 44 s with CI's --timeout-factor=40, against 2 to 3 s without the factor.

Without the sleep, the last check still failed locally when I made the node read the pings. Wouldn't it be better for the sleep to be one second?

The test takes 42 to 44 s with CI's `--timeout-factor=40`, against 2 to 3 s without the factor. Without the sleep, the last check still failed locally when I made the node read the pings. Wouldn't it be better for the sleep to be one second?
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36963
No description provided.