1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Add RecordError

This commit is contained in:
Vladimir Mihailenco
2020-07-09 10:39:46 +03:00
parent dd5e03f960
commit 1831363467
3 changed files with 34 additions and 23 deletions

View File

@ -63,11 +63,13 @@ func (cn *Conn) RemoteAddr() net.Addr {
func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error {
return internal.WithSpan(ctx, "with_reader", func(ctx context.Context) error {
err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout))
if err != nil {
return err
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
return internal.RecordError(ctx, err)
}
return fn(cn.rd)
if err := fn(cn.rd); err != nil {
return internal.RecordError(ctx, err)
}
return nil
})
}
@ -75,21 +77,23 @@ func (cn *Conn) WithWriter(
ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
) error {
return internal.WithSpan(ctx, "with_writer", func(ctx context.Context) error {
err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout))
if err != nil {
return err
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
return internal.RecordError(ctx, err)
}
if cn.bw.Buffered() > 0 {
cn.bw.Reset(cn.netConn)
}
err = fn(cn.wr)
if err != nil {
return err
if err := fn(cn.wr); err != nil {
return internal.RecordError(ctx, err)
}
return cn.bw.Flush()
if err := cn.bw.Flush(); err != nil {
return internal.RecordError(ctx, err)
}
return nil
})
}