The Contribution
Introduced safer and more graceful error handling in Surfpool's Simnet threading flow.
Changes Made
Error Propagation
- Replaced process exit with event-based error propagation in simnet thread
- Allow graceful error handling through the event channel instead of abrupt termination
Port Availability
- Added port availability validation before starting RPC and WebSocket servers
- Extracted port checking logic into reusable
check_port_availability function
Better Error Messages
- Print error messages to stderr for better visibility when ports are in use
- Provide clearer error messages when address binding fails
Code Cleanup
- Removed unnecessary sleep and direct process exit calls
Impact
The changes make the Simnet more robust by:
- Preventing crashes when ports are already in use
- Providing clear feedback to users about what went wrong
- Allowing the application to handle errors gracefully instead of terminating abruptly
What I Learned
- Rust error handling patterns
- Network programming and port management
- Event-driven architecture in threaded applications