fix: improve port discovery resilience and cleanup - #6
Conversation
nicksenap
commented
Feb 10, 2026
- Continue scanning on any port error, not just EADDRINUSE
- Wait for failed WebSocketServer to close before rejecting
- Continue scanning on any port error, not just EADDRINUSE - Wait for failed WebSocketServer to close before rejecting Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR Review: fix: improve port discovery resilience and cleanupSummaryThis PR makes two focused improvements to the WebSocket server port discovery logic:
✅ Code Quality & Best PracticesExcellent changes overall. The code follows project conventions:
Minor suggestion: Consider extracting the error code for better readability: const code = (err as NodeJS.ErrnoException).code;This is already done in the PR—great! ✓ ✅ Correctness & Bug FixesFix #1: Continue on all port errors
Fix #2: Callback-based close in wss.close(() => reject(err));
✅ Performance ConsiderationsNo performance concerns. Changes are minimal and the async close adds negligible overhead while improving reliability. ✅ Security ConcernsNo security issues. The changes improve error handling resilience without introducing vulnerabilities. 🧪 Test Coverage AssessmentCurrent test coverage is strong (packages/mcp-server/src/extension-bridge/websocket-server.test.ts):
Gap identified: The new behavior (continuing on non- Recommendation: Add a test case like: it('should continue scanning on non-EADDRINUSE errors', async () => {
// Simulate EACCES or other error on first port
// Verify it continues to next port instead of throwing
});This would be valuable but not blocking—the existing port discovery tests provide good confidence. 📋 Summary
RecommendationApprove with optional enhancement. The changes are solid and improve resilience. Consider adding a test for the new error-handling behavior in a follow-up if desired, but not required for merge. Great work on improving the multi-instance support! 🎉 |
Verifies that the server continues scanning on errors like EACCES instead of crashing, by mocking tryPort to reject with a custom code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2c1f82d to
8783403
Compare
Code Review: PR #6 - Improve port discovery resilience and cleanupSummaryThis PR improves the robustness of the WebSocket server's port discovery mechanism by handling all port binding errors (not just ✅ Strengths1. Improved Resilience 2. Better Error Cleanup (websocket-server.ts:65) 3. Comprehensive Test Coverage 4. Consistent Logging 🔍 Code Quality ObservationsWell-Structured Changes
Test Quality
💭 Minor Considerations1. Test Brittleness (websocket-server.test.ts:199) 2. Error Code Undefined (websocket-server.ts:83) 3. Continue Statement Behavior (websocket-server.ts:89) 🔒 SecurityNo security concerns. The changes are defensive and improve error handling. ⚡ PerformanceNo performance impact. Error handling in the startup path is not performance-critical. 🧪 Test CoverageExcellent coverage for the new behavior:
The existing tests for 📋 Suggestions (Non-Blocking)
✨ VerdictLGTM ✅ This is a clean, well-tested improvement that makes the port discovery more robust. The changes are minimal, focused, and follow the project's conventions. The test coverage properly validates the new behavior. Recommendation: Merge with confidence. Review generated by Claude Code following CLAUDE.md conventions |
Pull Request Review: Port Discovery ResilienceSummaryThis PR improves the WebSocket server's port discovery by making it more resilient to various error conditions beyond just ✅ Strengths
🔍 Code Qualitywebsocket-server.ts (lines 82-90)Good practices:
Minor consideration: ```typescript However, this is very minor since WebSocket server errors typically include error codes. websocket-server.test.ts (lines 188-211)Test design:
Type safety: 🔒 Security ConsiderationsNo security concerns identified. The changes:
⚡ Performance ConsiderationsPerformance impact is negligible:
🧪 Test CoverageCoverage is good:
Could be enhanced (optional): 📋 Suggestions1. Consider logging the full error for debuggingIn the catch block, you might want to log more details for unexpected errors: ```typescript 2. Documentation updateConsider adding a comment in the code explaining why all errors result in continuing to the next port: ```typescript ✅ VerdictThis PR is ready to merge. The changes are:
The suggestions above are optional enhancements and should not block merging. Alignment with CLAUDE.md conventions:
|