X-Git-Url: https://git.giacomolli.uk/onehouse/blobdiff_plain/ed48ff78adf6b195fc729e6c58772edc3a09def2..d1910130620af1355128795e5dbcacab4f476950:/driver/m31/tcp_client.go?ds=sidebyside diff --git a/driver/m31/tcp_client.go b/driver/m31/tcp_client.go index 6484b10..972f698 100644 --- a/driver/m31/tcp_client.go +++ b/driver/m31/tcp_client.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "net" + "os" "time" ) @@ -204,6 +205,10 @@ func (c *tcpClient) exchange(ctx context.Context, function byte, data []byte) (r if !stop() { <-interrupted + if err == nil || deadlineOnly(err) { + err = ctx.Err() + } + err = errors.Join(err, interruptErr, ctx.Err()) } }() @@ -265,3 +270,28 @@ func operationDeadline(ctx context.Context, timeout time.Duration) time.Time { return deadline } + +func deadlineOnly(err error) bool { + joined, ok := err.(interface{ Unwrap() []error }) + if ok { + found := false + + for _, cause := range joined.Unwrap() { + if cause != nil { + found = true + if !deadlineOnly(cause) { + return false + } + } + } + + return found + } + + wrapped, ok := err.(interface{ Unwrap() error }) + if ok { + return deadlineOnly(wrapped.Unwrap()) + } + + return errors.Is(err, os.ErrDeadlineExceeded) +}