Alanxtl commented on code in PR #3833:
URL: https://github.com/apache/dubbo-go/pull/3833#discussion_r4594404265
##########
remoting/getty/listener.go:
##########
@@ -272,6 +272,9 @@ func (h *RpcServerHandler) OnMessage(session getty.Session,
pkg any) {
attachments[constant.LocalAddr] = session.LocalAddr()
attachments[constant.RemoteAddr] = session.RemoteAddr()
+ reqCancel := h.bindRequestContext(session, invoc)
Review Comment:
`defer reqCancel()` 在整个 `OnMessage` 返回时才执行;双向请求的业务 handler 返回后,还要经过响应序列化和
`reply`。如果响应写入阻塞,业务 handler 派生的 goroutine 会继续看到有效的 context,直到写入结束或超时。这与 PR
描述的“handler 返回后释放 context”不一致。现有对应测试使用的是单向请求,覆盖不到这一情况。建议在 `requestHandler`
返回后立即取消,同时保留异常路径的清理。
##########
remoting/getty/listener.go:
##########
@@ -363,3 +362,84 @@ func heartbeat(session getty.Session, timeout
time.Duration, callBack func(err e
return perrors.WithStack(err)
}
+
+// releaseSession cancels the session-scoped context and drops the session
+// from the map. It is safe to call more than once.
+func (h *RpcServerHandler) releaseSession(session getty.Session) {
+ h.rwlock.Lock()
+ rs := h.sessionMap[session]
+ delete(h.sessionMap, session)
+ h.rwlock.Unlock()
+ if rs != nil && rs.cancel != nil {
+ rs.cancel()
+ }
+}
+
+// cancelAll cancels every session context, used when the server stops.
+func (h *RpcServerHandler) cancelAll() {
+ h.rwlock.Lock()
+ cancels := make([]context.CancelFunc, 0, len(h.sessionMap))
+ for session, rs := range h.sessionMap {
Review Comment:
`cancelAll` 从 `sessionMap` 删除所有 session,但 Getty 的服务端 `Close`
只关闭监听器,不会关闭已建立的连接。因此,旧连接仍能发送请求,而 `bindRequestContext` 找不到 session 后会为每个请求创建已取消的
context。依赖 context 的业务会持续失败;不检查 context 的业务则仍可能执行。连接没有断开,客户端也无法借此触发重连。
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]