@@ -20,8 +20,7 @@ use cortex_mcp_types::{
2020use tokio:: io:: { AsyncBufReadExt , AsyncWriteExt , BufReader } ;
2121use tokio:: process:: { Child , Command } ;
2222use tokio:: sync:: { Mutex , RwLock } ;
23- use tokio:: time:: sleep;
24- use tracing:: { debug, error, info, warn} ;
23+ use tracing:: { debug, info, warn} ;
2524
2625// ============================================================================
2726// Transport Trait
@@ -199,61 +198,6 @@ impl StdioTransport {
199198 Ok ( ( ) )
200199 }
201200
202- /// Reconnect with exponential backoff.
203- ///
204- /// Properly cleans up existing connections before each attempt to prevent
205- /// file descriptor leaks (#2198).
206- #[ allow( dead_code) ]
207- async fn reconnect ( & self ) -> Result < ( ) > {
208- if !self . reconnect_config . enabled {
209- return Err ( anyhow ! ( "Reconnection disabled" ) ) ;
210- }
211-
212- let mut attempt = 0 ;
213- let mut delay = self . reconnect_config . initial_delay ;
214-
215- while attempt < self . reconnect_config . max_attempts {
216- attempt += 1 ;
217- info ! (
218- attempt,
219- max = self . reconnect_config. max_attempts,
220- "Attempting reconnection"
221- ) ;
222-
223- // Clean up any existing connection before attempting reconnect
224- // This prevents file descriptor leaks on repeated failures (#2198)
225- {
226- let mut process_guard = self . process . lock ( ) . await ;
227- if let Some ( mut child) = process_guard. take ( ) {
228- // Kill the process and wait for it to clean up
229- let _ = child. kill ( ) . await ;
230- // Wait a short time for resources to be released
231- drop ( child) ;
232- }
233- self . connected . store ( false , Ordering :: SeqCst ) ;
234- }
235-
236- // Clear any stale pending responses
237- self . pending_responses . write ( ) . await . clear ( ) ;
238-
239- match self . connect ( ) . await {
240- Ok ( ( ) ) => {
241- info ! ( "Reconnection successful" ) ;
242- return Ok ( ( ) ) ;
243- }
244- Err ( e) => {
245- error ! ( error = %e, attempt, "Reconnection failed" ) ;
246- if attempt < self . reconnect_config . max_attempts {
247- sleep ( delay) . await ;
248- delay = ( delay * 2 ) . min ( self . reconnect_config . max_delay ) ;
249- }
250- }
251- }
252- }
253-
254- Err ( anyhow ! ( "Failed to reconnect after {} attempts" , attempt) )
255- }
256-
257201 /// Send a request and wait for response.
258202 async fn send_request ( & self , request : JsonRpcRequest ) -> Result < JsonRpcResponse > {
259203 // Ensure connected
@@ -516,51 +460,6 @@ impl HttpTransport {
516460 fn next_request_id ( & self ) -> RequestId {
517461 RequestId :: Number ( self . request_id . fetch_add ( 1 , Ordering :: SeqCst ) as i64 )
518462 }
519-
520- /// Test connection.
521- #[ allow( dead_code) ]
522- async fn test_connection ( & self ) -> Result < ( ) > {
523- let request = JsonRpcRequest :: new ( self . next_request_id ( ) , methods:: PING ) ;
524- self . send_request ( request) . await ?;
525- Ok ( ( ) )
526- }
527-
528- /// Reconnect with exponential backoff.
529- #[ allow( dead_code) ]
530- async fn reconnect ( & self ) -> Result < ( ) > {
531- if !self . reconnect_config . enabled {
532- return Err ( anyhow ! ( "Reconnection disabled" ) ) ;
533- }
534-
535- let mut attempt = 0 ;
536- let mut delay = self . reconnect_config . initial_delay ;
537-
538- while attempt < self . reconnect_config . max_attempts {
539- attempt += 1 ;
540- info ! (
541- attempt,
542- max = self . reconnect_config. max_attempts,
543- "Attempting HTTP reconnection"
544- ) ;
545-
546- match self . test_connection ( ) . await {
547- Ok ( ( ) ) => {
548- info ! ( "HTTP reconnection successful" ) ;
549- self . connected . store ( true , Ordering :: SeqCst ) ;
550- return Ok ( ( ) ) ;
551- }
552- Err ( e) => {
553- error ! ( error = %e, attempt, "HTTP reconnection failed" ) ;
554- if attempt < self . reconnect_config . max_attempts {
555- sleep ( delay) . await ;
556- delay = ( delay * 2 ) . min ( self . reconnect_config . max_delay ) ;
557- }
558- }
559- }
560- }
561-
562- Err ( anyhow ! ( "Failed to reconnect after {} attempts" , attempt) )
563- }
564463}
565464
566465#[ async_trait]
0 commit comments