charlesdong1991 commented on code in PR #399:
URL: https://github.com/apache/fluss-rust/pull/399#discussion_r2880367381


##########
crates/fluss/src/rpc/server_connection.rs:
##########
@@ -388,10 +408,36 @@ where
 
         self.send_message(buf).await?;
         _cleanup_on_cancel.message_sent();
-        let mut response = rx.await.map_err(|e| Error::UnexpectedError {
-            message: "Got recvError, some one close the channel".to_string(),
-            source: Some(Box::new(e)),
-        })??;
+        let mut response = match self.request_timeout {
+            Some(timeout) => match tokio::time::timeout(timeout, rx).await {
+                Ok(result) => result.map_err(|e| Error::UnexpectedError {
+                    message: format!(
+                        "Response channel closed for request_id={request_id} 
api_key={:?}; \
+                         connection may be closed or poisoned",
+                        R::API_KEY
+                    ),
+                    source: Some(Box::new(e)),
+                })??,
+                Err(_elapsed) => {
+                    if let ConnectionState::RequestMap(map) = 
self.state.lock().deref_mut() {
+                        map.remove(&request_id);
+                    }
+                    return Err(RpcError::RequestTimeout {
+                        timeout,
+                        api_key: R::API_KEY,
+                    }
+                    .into());
+                }
+            },
+            None => rx.await.map_err(|e| Error::UnexpectedError {

Review Comment:
   changed, avoided duplication



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to