fix(sdk): conn SetReadDeadline and reader specify ctx. #1000151163

Signed-off-by: baihailong <baihailong@oppo.com>
This commit is contained in:
baihailong 2025-07-16 17:24:22 +08:00 committed by chihe
parent c3b0722c7a
commit 8fb8ae389c

View File

@ -974,19 +974,25 @@ type RemoteCacheReader struct {
needReadLen int64
alreadyReadLen int64
reqID string
ctx context.Context
}
func (rc *RemoteCacheClient) NewRemoteCacheReader(conn *net.TCPConn, reqID string) *RemoteCacheReader {
func (rc *RemoteCacheClient) NewRemoteCacheReader(ctx context.Context, conn *net.TCPConn, reqID string) *RemoteCacheReader {
r := &RemoteCacheReader{
conn: conn,
reader: bufio.NewReaderSize(conn, proto.CACHE_BLOCK_PACKET_SIZE),
rc: rc,
reqID: reqID,
ctx: ctx,
}
return r
}
func (reader *RemoteCacheReader) Read(p []byte) (n int, err error) {
if reader.ctx.Err() != nil {
log.LogErrorf("RemoteCacheReader:reqID(%v) err(%v)", reader.reqID, err)
return 0, reader.ctx.Err()
}
reply := new(proto.Packet)
var expectLen int64
@ -1146,8 +1152,7 @@ func (rc *RemoteCacheClient) ReadObject(ctx context.Context, fg *FlashGroup, req
fg.moveToUnknownRank(addr, err, rc.FlashNodeTimeoutCount)
return nil, 0, err
}
conn.SetReadDeadline(time.Time{})
reader = rc.NewRemoteCacheReader(conn, reqId)
reader = rc.NewRemoteCacheReader(ctx, conn, reqId)
reader.needReadLen = int64(req.Size_)
break
}