Skip to content

Commit 7aa279e

Browse files
author
Max Maximov
committed
fix: use wrapped context err when <-ctx.Done() case is executed
1 parent 47f0e5d commit 7aa279e

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1414

1515
### Fixed
1616

17+
- Use wrapped context err when <-ctx.Done() case is executed
18+
1719
## [v2.4.0] - 2025-07-11
1820

1921
This release focuses on adding schema/user/session operations, synchronous transaction

connection.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,10 @@ func (conn *Connection) newFuture(req Request) (fut *Future) {
984984
if ctx != nil {
985985
select {
986986
case <-ctx.Done():
987-
fut.SetError(fmt.Errorf("context is done (request ID %d)", fut.requestId))
987+
fut.SetError(fmt.Errorf(
988+
"context is done (request ID %d): %w",
989+
fut.requestId, context.Cause(ctx),
990+
))
988991
shard.rmut.Unlock()
989992
return
990993
default:
@@ -1026,7 +1029,10 @@ func (conn *Connection) contextWatchdog(fut *Future, ctx context.Context) {
10261029
case <-fut.done:
10271030
return
10281031
default:
1029-
conn.cancelFuture(fut, fmt.Errorf("context is done (request ID %d)", fut.requestId))
1032+
conn.cancelFuture(fut, fmt.Errorf(
1033+
"context is done (request ID %d): %w",
1034+
fut.requestId, context.Cause(ctx),
1035+
))
10301036
}
10311037
}
10321038

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
type Tuple struct {
1717
// Instruct msgpack to pack this struct as array, so no custom packer
1818
// is needed.
19-
_msgpack struct{} `msgpack:",asArray"` //nolint: structcheck,unused
19+
_msgpack struct{} `msgpack:",asArray"` // nolint: structcheck,unused
2020
Id uint
2121
Msg string
2222
Name string
@@ -167,7 +167,7 @@ func ExamplePingRequest_Context() {
167167
fmt.Println("Ping Error", regexp.MustCompile("[0-9]+").ReplaceAllString(err.Error(), "N"))
168168
// Output:
169169
// Ping Resp data []
170-
// Ping Error context is done (request ID N)
170+
// Ping Error context is done (request ID N): context deadline exceeded
171171
}
172172

173173
func ExampleSelectRequest() {

tarantool_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Member struct {
4848
Val uint
4949
}
5050

51-
var contextDoneErrRegexp = regexp.MustCompile(`^context is done \(request ID [0-9]+\)$`)
51+
var contextDoneErrRegexp = regexp.MustCompile(`^context is done \(request ID [0-9]+\):.+$`)
5252

5353
func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error {
5454
if err := e.EncodeArrayLen(2); err != nil {
@@ -89,8 +89,8 @@ var indexNo = uint32(0)
8989
var indexName = "primary"
9090
var opts = Opts{
9191
Timeout: 5 * time.Second,
92-
//Concurrency: 32,
93-
//RateLimit: 4*1024,
92+
// Concurrency: 32,
93+
// RateLimit: 4*1024,
9494
}
9595

9696
const N = 500
@@ -888,7 +888,7 @@ func TestFutureMultipleGetTypedWithError(t *testing.T) {
888888
}
889889
}
890890

891-
///////////////////
891+
// /////////////////
892892

893893
func TestClient(t *testing.T) {
894894
var err error
@@ -2716,7 +2716,7 @@ func TestCallRequest(t *testing.T) {
27162716
func TestClientRequestObjectsWithNilContext(t *testing.T) {
27172717
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
27182718
defer conn.Close()
2719-
req := NewPingRequest().Context(nil) //nolint
2719+
req := NewPingRequest().Context(nil) // nolint
27202720
data, err := conn.Do(req).Get()
27212721
if err != nil {
27222722
t.Fatalf("Failed to Ping: %s", err)
@@ -3269,7 +3269,7 @@ func TestClientIdRequestObjectWithNilContext(t *testing.T) {
32693269
req := NewIdRequest(ProtocolInfo{
32703270
Version: ProtocolVersion(1),
32713271
Features: []iproto.Feature{iproto.IPROTO_FEATURE_STREAMS},
3272-
}).Context(nil) //nolint
3272+
}).Context(nil) // nolint
32733273
data, err := conn.Do(req).Get()
32743274
require.Nilf(t, err, "No errors on Id request execution")
32753275
require.NotNilf(t, data, "Response data not empty")
@@ -3293,7 +3293,7 @@ func TestClientIdRequestObjectWithPassedCanceledContext(t *testing.T) {
32933293
req := NewIdRequest(ProtocolInfo{
32943294
Version: ProtocolVersion(1),
32953295
Features: []iproto.Feature{iproto.IPROTO_FEATURE_STREAMS},
3296-
}).Context(ctx) //nolint
3296+
}).Context(ctx) // nolint
32973297
cancel()
32983298
resp, err := conn.Do(req).Get()
32993299
require.Nilf(t, resp, "Response is empty")

0 commit comments

Comments
 (0)