Skip to content

Commit 94dd3c0

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

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
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: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ConnLogKind int
3636

3737
var (
3838
errUnknownRequest = errors.New("the passed connected request doesn't belong " +
39-
"to the current connection or connection pool")
39+
"to the current connection or connection pool")
4040
)
4141

4242
const (
@@ -113,7 +113,7 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
113113
case LogUnexpectedResultId:
114114
header := v[0].(Header)
115115
log.Printf("tarantool: connection %s got unexpected request ID (%d) in response "+
116-
"(probably cancelled request)",
116+
"(probably cancelled request)",
117117
conn.Addr(), header.RequestId)
118118
case LogWatchEventReadFailed:
119119
err := v[0].(error)
@@ -515,8 +515,8 @@ func (conn *Connection) dial(ctx context.Context) error {
515515

516516
// Subscribe shutdown event to process graceful shutdown.
517517
if conn.shutdownWatcher == nil &&
518-
isFeatureInSlice(iproto.IPROTO_FEATURE_WATCHERS,
519-
conn.serverProtocolInfo.Features) {
518+
isFeatureInSlice(iproto.IPROTO_FEATURE_WATCHERS,
519+
conn.serverProtocolInfo.Features) {
520520
watcher, werr := conn.newWatcherImpl(shutdownEventKey, shutdownEventCallback)
521521
if werr != nil {
522522
return werr
@@ -528,7 +528,7 @@ func (conn *Connection) dial(ctx context.Context) error {
528528
}
529529

530530
func pack(h *smallWBuf, enc *msgpack.Encoder, reqid uint32,
531-
req Request, streamId uint64, res SchemaResolver) (err error) {
531+
req Request, streamId uint64, res SchemaResolver) (err error) {
532532
const uint32Code = 0xce
533533
const uint64Code = 0xcf
534534
const streamBytesLenUint64 = 10
@@ -665,7 +665,7 @@ func (conn *Connection) runReconnects(ctx context.Context) error {
665665
return err
666666
}
667667
if clientErr, ok := err.(ClientError); ok &&
668-
clientErr.Code == ErrConnectionClosed {
668+
clientErr.Code == ErrConnectionClosed {
669669
return err
670670
}
671671
} else {
@@ -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

@@ -1228,9 +1234,9 @@ func read(r io.Reader, lenbuf []byte) (response []byte, err error) {
12281234
return
12291235
}
12301236
length = (uint64(lenbuf[1]) << 24) +
1231-
(uint64(lenbuf[2]) << 16) +
1232-
(uint64(lenbuf[3]) << 8) +
1233-
uint64(lenbuf[4])
1237+
(uint64(lenbuf[2]) << 16) +
1238+
(uint64(lenbuf[3]) << 8) +
1239+
uint64(lenbuf[4])
12341240

12351241
switch {
12361242
case length == 0:
@@ -1279,8 +1285,8 @@ func (conn *Connection) ConfiguredTimeout() time.Duration {
12791285
func (conn *Connection) SetSchema(s Schema) {
12801286
sCopy := s.copy()
12811287
spaceAndIndexNamesSupported :=
1282-
isFeatureInSlice(iproto.IPROTO_FEATURE_SPACE_AND_INDEX_NAMES,
1283-
conn.serverProtocolInfo.Features)
1288+
isFeatureInSlice(iproto.IPROTO_FEATURE_SPACE_AND_INDEX_NAMES,
1289+
conn.serverProtocolInfo.Features)
12841290

12851291
conn.mutex.Lock()
12861292
defer conn.mutex.Unlock()
@@ -1463,7 +1469,7 @@ func (conn *Connection) NewWatcher(key string, callback WatchCallback) (Watcher,
14631469
if !isFeatureInSlice(iproto.IPROTO_FEATURE_WATCHERS,
14641470
conn.serverProtocolInfo.Features) {
14651471
err := fmt.Errorf("the feature %s must be supported by connection "+
1466-
"to create a watcher", iproto.IPROTO_FEATURE_WATCHERS)
1472+
"to create a watcher", iproto.IPROTO_FEATURE_WATCHERS)
14671473
return nil, err
14681474
}
14691475

0 commit comments

Comments
 (0)