New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patch configuration and log actual port on startup #3160
Conversation
Before this change, the application ```swift let app = Application(.testing) defer { app.shutdown() } try app.server.start(hostname: nil, port: 0) defer { app.server.shutdown() } ``` would log the following message *before* starting the server: ``` [Vapor] Server starting on http://127.0.0.1:0 ``` After this change it instead logs a message like the following *after* starting the server: ``` [Vapor] Server started on [IPv4]127.0.0.1/127.0.0.1:57935 ```
I have no experience with this code base so I'm just guessing that it's safe to force unwrap I also realize that the log message is now less readable and doesn't include the protocol. This was just the simplest possible solution I could come up with. I'll be happy to change it. Looking forward to your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just a couple of nits left
Just invoking the property twice seemed cleaner to me compared to duplicating the code block. Fixed a little indentation issue in the process I don't know if it's ever relevant, but config is now patched on all address types, including unix socket.
Ping @0xTim :) |
@0xTim Is there anything that needs to change before this can get merged? If you disagree with extracting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor change then good to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry one last thing to add - can you add a test for the configuration? Essentially run the server set to port 0 and then try and read the port from the configuration and make sure it isn't 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@bisgardo the new test is failing |
Head branch was pushed to by a user without write access
It was an existing test, not the new one. I've pushed a fix. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3160 +/- ##
==========================================
+ Coverage 76.86% 77.44% +0.57%
==========================================
Files 211 210 -1
Lines 8119 7822 -297
==========================================
- Hits 6241 6058 -183
+ Misses 1878 1764 -114
|
* main: Patch configuration and log actual port on startup (vapor#3160) Update provider tests to 5.10 (vapor#3178) Migrate to Async NIOFileIO APIs (vapor#3167) Removed streamFile deprecation + deactivated advancedETagComparison by default (vapor#3177) Remove HeadResponder (vapor#3147) Advanced ETag Comparison now supported (vapor#3015) Enabled Request Decompression By Default (vapor#3175) HTTP2 Response Compression/Request Decompression (vapor#3126) Don't set ignore status for SIGTERM and SIGINT on Linux (vapor#3174) Fix typos across the codebase (vapor#3162) Fix some Sendable warnings on 5.10 (vapor#3158) Allow `HTTPServer`'s configuration to be dynamically updatable (vapor#3132) Fix issue when client disconnects midway through a stream (vapor#3102) Fix handling of "flag" URL query params (vapor#3151) Bump the dependencies group with 1 update (vapor#3148) Merge Async Tests (vapor#3141) Fix URI handling with multiple slashes and variable components. (vapor#3143) Fix broken URI behaviors (vapor#3140) # Conflicts: # Package.swift
These changes are now available in 4.94.1
Before this change, the application
would log the following message before starting the server:
After this change it instead logs a message like the following after starting the server:
The input configuration is also patched such that
app.http.server.configuration.port
will hold the actual port after startup. Currently if it has value 0 it will keep that value (onlyapp.http.server.shared.localAddress?.port
will have the correct one).Fixes #3159.