Skip to content

[breaking] make socket bind async#325

Merged
Guest0x0 merged 1 commit intomainfrom
async-bind
Apr 1, 2026
Merged

[breaking] make socket bind async#325
Guest0x0 merged 1 commit intomainfrom
async-bind

Conversation

@Guest0x0
Copy link
Copy Markdown
Collaborator

@Guest0x0 Guest0x0 commented Apr 1, 2026

It turns out that the socket bind operation can be time-consuming sometimes, lasting for several dozen milliseconds. This is causing random test failure on the CI, due to long-running bind messing timer precision up. This PR makes bind operations on socket async by running them in the thread pool. As a result, @socket.TcpServer::new, @socket.UdpServer::new and @http.Server::new become async as well, making this PR a breaking change.

bind is not a very heavy operation, so running it in the thread pool may actually be slower in terms of delay. However, bind is usually not a frequent operation: most programs won't create a lot of servers simultaneously and repeatedly. So the rationale here is to trade delay for better scheduling fairness.

@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 161

Details

  • 8 of 9 (88.89%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.06%) to 78.04%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/socket/tcp.mbt 3 4 75.0%
Totals Coverage Status
Change from base Build 160: 0.06%
Covered Lines: 2516
Relevant Lines: 3224

💛 - Coveralls

@Guest0x0 Guest0x0 merged commit 6ae57f0 into main Apr 1, 2026
17 checks passed
@Guest0x0 Guest0x0 deleted the async-bind branch April 1, 2026 06:43
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.

2 participants