XnLemon commented on code in PR #3579:
URL: https://github.com/apache/dubbo-go/pull/3579#discussion_r3763747761
##########
protocol/jsonrpc/server.go:
##########
@@ -79,14 +79,20 @@ func NewServer() *Server {
}
func (s *Server) handlePkg(conn net.Conn) {
+ connectionCtx, connectionCancel :=
context.WithCancel(context.Background())
+ writeConn := &lockedConn{Conn: conn}
+ var requestWG sync.WaitGroup
defer func() {
if r := recover(); r != nil {
logger.Warnf("[Jsonrpc][Server] connection panic,
local=%v, remote=%v, err=%v, debug stack=%s",
conn.LocalAddr(), conn.RemoteAddr(), r,
string(debug.Stack()))
}
conn.Close()
+ requestWG.Wait()
}()
+ // Register this after the cleanup defer so LIFO ordering cancels
request contexts before Wait.
+ defer connectionCancel()
Review Comment:
Fixed in 7ec7a877. Each invocation now builds its complete HTTP response in
a request-local buffer, and a single per-connection writer flushes completed
responses by request sequence. The connection read loop remains asynchronous
for disconnect cancellation, and it now reuses one buffered reader so pipelined
requests already read ahead are preserved.\n\nAdded
TestHandlePkgPreservesPipelinedResponseOrder: request 1 blocks while request 2
completes and encodes first; the test verifies no response is written until
request 1 is released, followed by response IDs 1 then 2. The order test passed
50 consecutive runs, and the disconnect/order tests passed under the race
detector.
--
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]