Skip to content

fix(http): add synchronous port binding to avoid false positive server start#2730

Merged
StarpTech merged 2 commits intomainfrom
dustin/check-port-server
Apr 2, 2026
Merged

fix(http): add synchronous port binding to avoid false positive server start#2730
StarpTech merged 2 commits intomainfrom
dustin/check-port-server

Conversation

@StarpTech
Copy link
Copy Markdown
Contributor

@StarpTech StarpTech commented Apr 2, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for server initialization with immediate detection of port binding failures and clearer error messages on startup.
  • Tests

    • Added test coverage for server initialization and port binding scenarios.

Checklist

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9b4ecb0a-3074-44d2-adce-784364851f1c

📥 Commits

Reviewing files that changed from the base of the PR and between fe662bf and c125958.

📒 Files selected for processing (3)
  • router/core/http_server.go
  • router/core/http_server_test.go
  • router/core/router.go

Walkthrough

This PR modifies the HTTP server initialization flow to synchronously bind TCP ports during newServer instead of deferring binding to listenAndServe. The newServer function now returns an error on binding failure, which is propagated through the router's NewServer and Start methods. New test cases validate error handling for port binding failures and successes.

Changes

Cohort / File(s) Summary
Server Binding Logic
router/core/http_server.go
Refactored newServer to synchronously bind address using net.Listen("tcp", ...), return (*server, error), store listener as struct field, and updated listenAndServe to serve via pre-bound listener instead of ListenAndServe/ListenAndServeTLS.
Error Handling
router/core/router.go
Updated NewServer and Start methods to capture and propagate errors from newServer with wrapped error messages (failed to create server).
Port Binding Tests
router/core/http_server_test.go
Added three test cases: TestNewServer_PortBindingError (validates immediate error on already-bound address), TestNewServer_PortBindingSuccess (validates successful binding and cleanup), and TestRouter_Start_PortBindingError (validates router startup failure propagation).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • fix: add back NewServer #2546: Modifies router startup and server creation handling in router/core/router.go with overlapping initialization paths and error propagation logic.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding synchronous port binding to prevent false positive server starts, which aligns with the core implementation changes across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@StarpTech StarpTech changed the title fix(http): add synchronous port binding to avoid running server twice fix(http): add synchronous port binding to avoid false positive server start Apr 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-94e0b7b43eb2b5baf1d1a109011ffde320540a5f

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.35%. Comparing base (bcb4ed3) to head (c125958).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
router/core/http_server.go 75.00% 0 Missing and 2 partials ⚠️
router/core/router.go 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2730       +/-   ##
===========================================
+ Coverage   45.69%   63.35%   +17.65%     
===========================================
  Files        1032      249      -783     
  Lines      138960    26671   -112289     
  Branches     8629        0     -8629     
===========================================
- Hits        63504    16898    -46606     
+ Misses      73731     8408    -65323     
+ Partials     1725     1365      -360     
Files with missing lines Coverage Δ
router/core/http_server.go 86.76% <75.00%> (+0.82%) ⬆️
router/core/router.go 69.99% <75.00%> (+0.20%) ⬆️

... and 787 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@StarpTech StarpTech merged commit 91e7f46 into main Apr 2, 2026
37 checks passed
@StarpTech StarpTech deleted the dustin/check-port-server branch April 2, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants