Skip to content

Conversation

@0xB10C
Copy link
Contributor

@0xB10C 0xB10C commented Jan 10, 2026

As TCP is buffered and asynchronous at the OS level, the first protocol.write() to a closed socket can succeed for both sync and async. The second write will fail.

As this confused me in #161, and I assumed it's a bug, document this here by having test coverage for it.

closes #161

0xB10C added 2 commits January 9, 2026 15:40
This implements the sync variant of 0719bcc.
While this works at the moment, I think it's good to have this test for
extra coverage. It can also be easily extended in a follow up to test
sync write() on a closed socket (see rust-bitcoin#160 (comment)).
As TCP is buffered and asynchronous at the OS level, the first
protocol.write() to a closed socket can succeed for both sync and
async. The second write will fail.

As this confused me in rust-bitcoin#161, and I assumed it's a bug, document this
here by having test coverage for it.

closes rust-bitcoin#161
@0xB10C
Copy link
Contributor Author

0xB10C commented Jan 10, 2026

Draft as the first commit is from #163. Will rebase once that's merged.

Also, I don't think having this is super important. Feel free to close if you'd rather not have it.

@0xB10C
Copy link
Contributor Author

0xB10C commented Jan 10, 2026

As TCP is buffered and asynchronous at the OS level, the first protocol.write() to a closed socket can succeed for both sync and async. The second write will fail.

Well.. at least on Linux I guess. Not on Windows?

Writing to the closed socket for the first time should succeed.

thread 'pingpong_with_closed_connection_sync' panicked at protocol\tests\round_trips.rs:243:10:
first write to closed socket should succeed!: Io(Os { code: 10054, kind: ConnectionReset, message: "An existing connection was forcibly closed by the remote host." }, RetryV1)

@0xB10C
Copy link
Contributor Author

0xB10C commented Jan 10, 2026

Going to close this. I did a few runs in https://github.com/0xB10C/bip324/actions/runs/20881650088?pr=4 and this seems brittle. I don't think it's important enough at the moment. Just be aware that writing to a socket and getting Ok() might not mean that socket is still alive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: async protocol.write(X).await on closed socket does not error

1 participant