From a66b15d6c84beb22b52fd020700641c8e7eebec2 Mon Sep 17 00:00:00 2001 From: Houmgaor Date: Fri, 30 Jan 2026 01:02:43 +0100 Subject: [PATCH] fix(stage): add timeout to WaitStageBinary handler Cherry-picked from main (c539905). Prevents infinite loop when stage binary data never arrives by limiting to 10 iterations (10 seconds) before returning empty response. --- server/channelserver/handlers_stage.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/channelserver/handlers_stage.go b/server/channelserver/handlers_stage.go index 8ee77478c..93cc10ce3 100644 --- a/server/channelserver/handlers_stage.go +++ b/server/channelserver/handlers_stage.go @@ -376,7 +376,7 @@ func handleMsgSysWaitStageBinary(s *Session, p mhfpacket.MHFPacket) { doAckBufSucceed(s, pkt.AckHandle, []byte{0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) return } - for { + for i := 0; i < 10; i++ { s.logger.Debug("MsgSysWaitStageBinary before lock and get stage") stage.Lock() stageBinary, gotBinary := stage.rawBinaryData[stageBinaryKey{pkt.BinaryType0, pkt.BinaryType1}] @@ -384,13 +384,15 @@ func handleMsgSysWaitStageBinary(s *Session, p mhfpacket.MHFPacket) { s.logger.Debug("MsgSysWaitStageBinary after lock and get stage") if gotBinary { doAckBufSucceed(s, pkt.AckHandle, stageBinary) - break + return } else { s.logger.Debug("Waiting stage binary", zap.Uint8("BinaryType0", pkt.BinaryType0), zap.Uint8("pkt.BinaryType1", pkt.BinaryType1)) time.Sleep(1 * time.Second) continue } } + s.logger.Warn("MsgSysWaitStageBinary stage binary timeout") + doAckBufSucceed(s, pkt.AckHandle, []byte{}) } else { s.logger.Warn("Failed to get stage", zap.String("StageID", pkt.StageID)) }