AlexStocks commented on code in PR #3833:
URL: https://github.com/apache/dubbo-go/pull/3833#discussion_r4596019448
##########
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:
补充取证:getty 的服务端 `Close` 确实不关闭已建立的连接,但据此推导的影响被 `Destroy` 的调用顺序削掉一层,建议把定级收到 P2
源码核对(`github.com/apache/[email protected]`):
- `server.stop()` 里 `s.server.Shutdown(ctx)` 只在 `s.server != nil` 时执行,而
`s.server` 是 `*http.Server`,仅 WS/WSS 端点非 nil;TCP 端点只走
`s.streamListener.Close()`(server.go)。
- `s.wg` 只 `Add(1)` 给了 `runTCPEventLoop` 的 accept 循环,各 `session.run()` 不在该
WaitGroup 内,所以 `Close()` 返回不代表已建立的会话结束。
因此"Stop 之后旧连接仍会派发 `OnMessage`、`bindRequestContext` 因 map 中已无该 session
而给出已取消的 parent"这一条成立,并且被
`TestServerRequestContextCanceledIfSessionAlreadyReleased/cancelAll before
bind` 固化成了预期行为。
但可观察影响需要收一层:getty `Server.Stop()` 在生产路径上只经
`remoting.ExchangeServer.Stop()`,而唯一调用方
`DubboProtocol.Destroy()`(dubbo_protocol.go)是**先**
`dp.BaseProtocol.Destroy()`(逐个 `Exporter.UnExport()`,见 base_protocol.go)**再**
`server.Stop()`。所以 Stop 之后旧连接上的请求会在 `doHandleRequest` 的 `ExporterMap().Load`
处先返回 `don't have this exporter`,`reply()` 仍把该错误写回;`context canceled`
不是第一个可观察到的失败点,客户端看到的是错误响应而非 canceled 语义。
据此建议定级 P2 而非 P1。本 PR 真正可补的是两处:
1. 在正文说明该窗口的观测表现(停止后旧连接上的请求以 "don't have this exporter" 失败,而非 ctx
取消),并说明"关闭既有会话"不放在本 PR 的原因;
2. "Stop 不关闭既有连接、心跳 goroutine 随进程存活"属于 getty 侧既有行为,建议另开 issue 记录,不要与本 PR 的
ctx 生命周期改造混在一起。
--
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]