Repository navigation
v7.2.3
Improved Connection Handling with Retries and Timeout
This update enhances the --connect command functionality by adding retry logic with timeouts and improving user feedback.
Key Changes:
-
Connection Retries: The
--connectcommand now attempts to establish a connection up toMAX_ATTEMPTS(currently 3) times. This improves resilience against transient network issues. -
Timeout per Attempt: Each connection attempt now has a timeout of 10 seconds, preventing the command from hanging indefinitely if the target is unreachable. This timeout is implemented using
tokio::time::timeout. -
Progress Bar Updates: The progress bar now provides more granular feedback during the connection process:
- It displays the current connection attempt number (e.g., "Connection attempt 1/3").
- It shows detailed error messages if a connection attempt fails (including the specific error).
- It indicates when a connection attempt times out.
-
Self-Connection Check: The code includes a check to prevent connecting to the node's own bind address unless the
--testflag is used. This prevents accidental self-connections. -
Immediate Sync After Connection: Upon successful connection, the code now immediately attempts to synchronize the chain using
handle_chain_sync. This ensures that the node is up-to-date with the network as soon as a connection is established. A warning is logged if the initial sync fails. -
Clearer Usage Instructions: The usage instructions for the
--connectcommand have been improved to be more user-friendly, including an example and an explanation of the--testflag.
Code Breakdown:
- The code uses a
whileloop to retry the connection up toMAX_ATTEMPTStimes. tokio::time::timeoutis used to implement the timeout for each connection attempt.- The progress bar (
ProgressBar) is updated with informative messages at each stage of the connection process. - The
node.verify_peerfunction is assumed to handle the actual connection and peer verification logic. - The
handle_chain_syncfunction is called after a successful connection to initiate chain synchronization.
Benefits:
- Improved Reliability: The retry logic makes the connection process more robust against temporary network issues.
- Prevented Deadlocks: The timeout prevents the command from hanging indefinitely.
- Better User Experience: The improved progress bar provides more detailed feedback to the user.
- Prevented Accidental Self-Connections: The self-connection check prevents common user errors.
- Ensured Immediate Sync: The immediate sync after connection ensures that the node is quickly brought up-to-date with the network.