Skip to content

Commit 5362b47

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

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
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: 30 additions & 30 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
@@ -727,7 +727,7 @@ func (req *mockRequest) Ctx() context.Context {
727727
}
728728

729729
func (req *mockRequest) Response(header Header,
730-
body io.Reader) (Response, error) {
730+
body io.Reader) (Response, error) {
731731
return nil, fmt.Errorf("some error")
732732
}
733733

@@ -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
@@ -1286,7 +1286,7 @@ func TestClientSessionPush(t *testing.T) {
12861286

12871287
const (
12881288
createTableQuery = "CREATE TABLE SQL_SPACE (ID STRING PRIMARY KEY, NAME " +
1289-
"STRING COLLATE \"unicode\" DEFAULT NULL);"
1289+
"STRING COLLATE \"unicode\" DEFAULT NULL);"
12901290
insertQuery = "INSERT INTO SQL_SPACE VALUES (?, ?);"
12911291
selectNamedQuery = "SELECT ID, NAME FROM SQL_SPACE WHERE ID=:ID AND NAME=:NAME;"
12921292
selectPosQuery = "SELECT ID, NAME FROM SQL_SPACE WHERE ID=? AND NAME=?;"
@@ -1568,9 +1568,9 @@ func TestSQLBindings(t *testing.T) {
15681568
metaData, err := exResp.MetaData()
15691569
assert.NoError(t, err, "Error while getting MetaData")
15701570
if metaData[0].FieldType != "unsigned" ||
1571-
metaData[0].FieldName != "NAME0" ||
1572-
metaData[1].FieldType != "string" ||
1573-
metaData[1].FieldName != "NAME1" {
1571+
metaData[0].FieldName != "NAME0" ||
1572+
metaData[1].FieldType != "string" ||
1573+
metaData[1].FieldName != "NAME1" {
15741574
t.Error("Wrong metadata")
15751575
}
15761576
}
@@ -1595,9 +1595,9 @@ func TestSQLBindings(t *testing.T) {
15951595
metaData, err := exResp.MetaData()
15961596
assert.NoError(t, err, "Error while getting MetaData")
15971597
if metaData[0].FieldType != "unsigned" ||
1598-
metaData[0].FieldName != "NAME0" ||
1599-
metaData[1].FieldType != "string" ||
1600-
metaData[1].FieldName != "NAME1" {
1598+
metaData[0].FieldName != "NAME0" ||
1599+
metaData[1].FieldType != "string" ||
1600+
metaData[1].FieldName != "NAME1" {
16011601
t.Error("Wrong metadata")
16021602
}
16031603

@@ -1621,9 +1621,9 @@ func TestSQLBindings(t *testing.T) {
16211621
metaData, err = exResp.MetaData()
16221622
assert.NoError(t, err, "Error while getting MetaData")
16231623
if metaData[0].FieldType != "unsigned" ||
1624-
metaData[0].FieldName != "NAME0" ||
1625-
metaData[1].FieldType != "string" ||
1626-
metaData[1].FieldName != "NAME1" {
1624+
metaData[0].FieldName != "NAME0" ||
1625+
metaData[1].FieldType != "string" ||
1626+
metaData[1].FieldName != "NAME1" {
16271627
t.Error("Wrong metadata")
16281628
}
16291629
}
@@ -1792,9 +1792,9 @@ func TestNewPrepared(t *testing.T) {
17921792
metaData, err := prepResp.MetaData()
17931793
assert.NoError(t, err, "Error while getting MetaData")
17941794
if metaData[0].FieldType != "unsigned" ||
1795-
metaData[0].FieldName != "NAME0" ||
1796-
metaData[1].FieldType != "string" ||
1797-
metaData[1].FieldName != "NAME1" {
1795+
metaData[0].FieldName != "NAME0" ||
1796+
metaData[1].FieldType != "string" ||
1797+
metaData[1].FieldName != "NAME1" {
17981798
t.Error("Wrong metadata")
17991799
}
18001800

@@ -1838,7 +1838,7 @@ func TestNewPrepared(t *testing.T) {
18381838

18391839
func TestConnection_DoWithStrangerConn(t *testing.T) {
18401840
expectedErr := fmt.Errorf("the passed connected request doesn't belong to the current" +
1841-
" connection or connection pool")
1841+
" connection or connection pool")
18421842

18431843
conn1 := &Connection{}
18441844
req := test_helpers.NewMockRequest()
@@ -2054,7 +2054,7 @@ func TestSchema(t *testing.T) {
20542054
t.Errorf("index field has incorrect Id")
20552055
}
20562056
if (ifield1.Type != "num" && ifield1.Type != "unsigned") ||
2057-
(ifield2.Type != "STR" && ifield2.Type != "string") {
2057+
(ifield2.Type != "STR" && ifield2.Type != "string") {
20582058
t.Errorf("index field has incorrect Type '%s'", ifield2.Type)
20592059
}
20602060
}
@@ -2506,7 +2506,7 @@ func testConnectionDoSelectRequestPrepare(t *testing.T, conn Connector) {
25062506
}
25072507

25082508
func testConnectionDoSelectRequestCheck(t *testing.T,
2509-
resp *SelectResponse, err error, pos bool, dataLen int, firstKey uint64) {
2509+
resp *SelectResponse, err error, pos bool, dataLen int, firstKey uint64) {
25102510
t.Helper()
25112511

25122512
if err != nil {
@@ -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)
@@ -2834,8 +2834,8 @@ func TestComplexStructs(t *testing.T) {
28342834
}
28352835

28362836
if tuple.Cid != tuples[0].Cid ||
2837-
len(tuple.Members) != len(tuples[0].Members) ||
2838-
tuple.Members[1].Name != tuples[0].Members[1].Name {
2837+
len(tuple.Members) != len(tuples[0].Members) ||
2838+
tuple.Members[1].Name != tuples[0].Members[1].Name {
28392839
t.Errorf("Failed to selectTyped: incorrect data")
28402840
return
28412841
}
@@ -3146,7 +3146,7 @@ func TestStream_TxnIsolationLevel(t *testing.T) {
31463146

31473147
func TestStream_DoWithStrangerConn(t *testing.T) {
31483148
expectedErr := fmt.Errorf("the passed connected request " +
3149-
"doesn't belong to the current connection or connection pool")
3149+
"doesn't belong to the current connection or connection pool")
31503150

31513151
conn := &Connection{}
31523152
stream, _ := conn.NewStream()
@@ -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")
@@ -3395,7 +3395,7 @@ func TestConnectionProtocolFeatureRequirementFail(t *testing.T) {
33953395
require.NotNilf(t, err, "Got error on connect")
33963396
require.Contains(t, err.Error(),
33973397
"invalid server protocol: protocol feature "+
3398-
"IPROTO_FEATURE_TRANSACTIONS is not supported")
3398+
"IPROTO_FEATURE_TRANSACTIONS is not supported")
33993399
}
34003400

34013401
func TestConnectionProtocolFeatureRequirementManyFail(t *testing.T) {
@@ -3416,7 +3416,7 @@ func TestConnectionProtocolFeatureRequirementManyFail(t *testing.T) {
34163416
require.Contains(t,
34173417
err.Error(),
34183418
"invalid server protocol: protocol features IPROTO_FEATURE_TRANSACTIONS, "+
3419-
"Feature(15532) are not supported")
3419+
"Feature(15532) are not supported")
34203420
}
34213421

34223422
func TestErrorExtendedInfoBasic(t *testing.T) {
@@ -3629,7 +3629,7 @@ func TestConnection_NewWatcher_noWatchersFeature(t *testing.T) {
36293629
require.Nilf(t, watcher, "watcher must not be created")
36303630
require.NotNilf(t, err, "an error is expected")
36313631
expected := "the feature IPROTO_FEATURE_WATCHERS must be supported by " +
3632-
"connection to create a watcher"
3632+
"connection to create a watcher"
36333633
require.Equal(t, expected, err.Error())
36343634
}
36353635

0 commit comments

Comments
 (0)