Repository navigation
feat: Retrieve actual port from Server instances (API and Insights servers) - #4021
Conversation
…rvers) Co-authored-by: SandPod <[email protected]>
Co-authored-by: SandPod <[email protected]>
SandPod
left a comment
There was a problem hiding this comment.
@coderabbitai full review
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughAdds a private _port field, a public port getter returning _ioServer?.port ?? _port, updates the Server constructor to accept int port and assign _port, and switches internal binding/error reporting to use _port or the bound port via _ioServer. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as Application
participant Server as Server
participant IO as _ioServer (HTTP)
rect rgba(230,240,255,0.5)
App->>Server: new Server(port)
Note right of Server: Store configured\nport in _port
App->>Server: start()
Server->>IO: bind(_port)
IO-->>Server: bound (port may differ, e.g., 0->random)
Note right of Server: _ioServer set\n(port reflects actual binding)
end
rect rgba(240,230,255,0.5)
App->>Server: get port
alt _ioServer bound
Server-->>App: _ioServer.port
else not yet bound
Server-->>App: _port
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Note Free review on us!CodeRabbit is offering free reviews until Wed Oct 08 2025 to showcase some of the refinements we've made. Comment |
|
@copilot please address or answer my review comments. |
Co-authored-by: SandPod <[email protected]>
marcelomendoncasoares
left a comment
There was a problem hiding this comment.
Just one comment regarding testing, if we think it's needed.
Summary
This PR implements the ability to retrieve the actual bound port from Server instances (both API and Insights servers) when using dynamic port allocation (port 0).
Changes Made
Modified
packages/serverpod/lib/src/server/server.dart:_actualPortfield to cache the actual bound port after server startsportgetter to return_actualPort ?? _port(cached value)start()method to set_actualPort = ioServer.portafter binding_portfield stores the configured port valueportas a parameter and initialize_port_portwhich is correct since binding hasn't succeeded yetportgetter which returns the actual bound portServers Fixed:
serverpod.server) - UsesServerclassserverpod.serviceServer) - UsesServerclassHow It Works
Before server starts:
_actualPortisnullportgetter returns_port(the configured port, could be 0 for dynamic allocation)After server starts:
_actualPortis set to the actual bound port fromioServer.portportgetter returns_actualPort(the cached actual port value)Use Cases Enabled
Implementation Details
The implementation follows the same pattern as PR #3775 for the WebServer:
_actualPortfield to cache the bound port after server startsTest Results
✅ All 713 unit tests in
packages/serverpodpass successfully✅ Code formatted and analyzed with no issues
✅ Existing integration tests already use
server.portandserviceServer.port, confirming backward compatibilityFixes #3949.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Summary by CodeRabbit
Bug Fixes
New Features