Skip to content

Commit 5c37e6f

Browse files
committed
fix(RPC): 修复RPC消息处理超时未返回错误响应的问题
在RPC消息处理中,当业务逻辑执行超时时,现在会正确设置超时错误码并返回错误响应给客户端,而不是直接忽略。这确保了客户端能够及时获得超时反馈。
1 parent 8d731fd commit 5c37e6f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

GameFrameX.Core/BaseHandler/RPC/BaseRpcMessageHandler.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,31 @@ public virtual async Task InnerAction(int timeout = 30000, CancellationToken can
105105
var response = MessageObjectPoolHelper.Get<TResponse>();
106106
var requestId = RequestMessage.UniqueId;
107107

108-
var task = InnerActionAsync(RequestMessage, response);
109-
110108
if (NetWorkChannel == null || NetWorkChannel.IsClosed() || response == null)
111109
{
112110
return;
113111
}
114112

115-
response.SetUniqueId(requestId);
116-
await NetWorkChannel.WriteAsync(response);
113+
var task = InnerActionAsync(RequestMessage, response);
114+
117115
try
118116
{
117+
// 先等待业务逻辑执行完成(包括超时检查)/ Wait for business logic to complete (including timeout check)
119118
await task.WaitAsync(TimeSpan.FromMilliseconds(timeout), cancellationToken);
119+
120+
// 业务逻辑执行成功后,设置响应ID并发送 / After successful execution, set response ID and send
121+
response.SetUniqueId(requestId);
122+
await NetWorkChannel.WriteAsync(response);
120123
}
121124
catch (TimeoutException timeoutException)
122125
{
123126
LogHelper.Fatal("执行超时:" + timeoutException.Message);
127+
128+
// 设置超时错误码并发送错误响应给客户端 / Set timeout error code and send error response to client
129+
response.ErrorCode = OperationErrorCode.TimeOut;
130+
response.SetUniqueId(requestId);
131+
await NetWorkChannel.WriteAsync(response);
132+
124133
//强制设状态-取消该操作
125134
}
126135
}

0 commit comments

Comments
 (0)