Repository navigation
log the requested endpoint when bind fails - #1272
Merged
Merged
Conversation
- The bind error was logged with `acceptor_.address()` and `acceptor_.port()`, which call `local_endpoint()` on the acceptor that the failed `bind` left unbound. - On Windows that call throws, so the original bind error is lost, `startup_failed_` is never set and `app.run()` throws. On Linux the message reports `0.0.0.0:0`. - Log the requested `endpoint` instead; Asio streams both the TCP and the Unix socket endpoint. - Add the `server_port_in_use` test: a bind to a port that another socket holds is logged with the requested address and port, and `run()` returns with `is_bound()` false. Fixes CrowCpp#1271
gittiver
approved these changes
Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1271.
When
bindfails in theServerconstructor, the error is logged withacceptor_.address()andacceptor_.port(). Both calllocal_endpoint()without an error code, on the acceptor that the failedbindleft unbound. On Windows, the call throws (WSAEINVAL) in the middle of the log statement: the original bind error is lost,startup_failed_is never set, andapp.run()throws instead of returning withis_bound()false. On Linux, it does not throw, but the message reports0.0.0.0:0instead of the requested address and port. This PR logs the requestedendpointinstead, as the line did before the Unix socket support (45d3fd5). Asio writes both endpoint types to a stream: a TCP endpoint as its address and port, a Unix socket endpoint as its path.The new test
server_port_in_use, next toserver_invalid_ip_address, holds a loopback port with a second socket (withoutSO_REUSEADDR) and serves the app on that port. It captures the log with anILogHandlerand checks thatrun()returns without an exception, thatis_bound()is false, and that the error line readsFailed to bind to 127.0.0.1:<port> - <reason>. It sets the log level it needs and restores the level and the default handler afterwards, so it does not depend on the order of the tests.Tested
local_endpoint: An invalid argument was supplied.) and passes after it.ctest -C Releasepasses (139 test cases).libasio-dev: the new test fails before the change (Failed to bind to 0.0.0.0:0 - Address already in use) and passes after it.ctestpasses (crow_testandtemplate_test).Not tested
CROW_USE_BOOSTand macOS were not tested locally. The CI matrix covers both.Thanks!