fix(rpc): timeout with response in rpc client for timer reset

@formatter:off

Signed-off-by: JasonHu520 <huzongchao@oppo.com>
This commit is contained in:
JasonHu520 2025-09-10 17:47:03 +08:00 committed by 梁曟風
parent d076024883
commit b4309236a2

View File

@ -357,6 +357,7 @@ type timeoutReadCloser struct {
timer *time.Timer
timeout time.Duration
closeOnce sync.Once
hasRead bool
}
func (tr *timeoutReadCloser) Close() (err error) {
@ -371,6 +372,14 @@ func (tr *timeoutReadCloser) Read(p []byte) (int, error) {
if tr.timeout <= 0 {
return 0, ErrBodyReadTimeout
}
if tr.hasRead {
select {
case <-tr.timer.C:
default:
}
}
tr.hasRead = true
tr.timer.Reset(tr.timeout)
start := time.Now()