Skip to content

Commit 06ed7f8

Browse files
api: more informative request canceling
Log the probable reason for unexpected requestId. Add requestId info to context done error message.
1 parent 0ccdee2 commit 06ed7f8

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1717
- Implemented stringer methods for pool.Role (#405).
1818

1919
### Changed
20+
- More informative request canceling: log the probable reason for unexpected requestId
21+
and add requestId info to context done error message.
2022

2123
### Fixed
2224

connection.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
100100
conn.Addr(), err)
101101
case LogUnexpectedResultId:
102102
header := v[0].(Header)
103-
log.Printf("tarantool: connection %s got unexpected resultId (%d) in response",
103+
log.Printf("tarantool: connection %s got unexpected resultId (%d) in response (probably canceled request)",
104104
conn.Addr(), header.RequestId)
105105
case LogWatchEventReadFailed:
106106
err := v[0].(error)
@@ -940,7 +940,7 @@ func (conn *Connection) newFuture(req Request) (fut *Future) {
940940
if ctx != nil {
941941
select {
942942
case <-ctx.Done():
943-
fut.SetError(fmt.Errorf("context is done"))
943+
fut.SetError(fmt.Errorf("context is done (requestId %d)", fut.requestId))
944944
shard.rmut.Unlock()
945945
return
946946
default:
@@ -982,7 +982,7 @@ func (conn *Connection) contextWatchdog(fut *Future, ctx context.Context) {
982982
case <-fut.done:
983983
return
984984
default:
985-
conn.cancelFuture(fut, fmt.Errorf("context is done"))
985+
conn.cancelFuture(fut, fmt.Errorf("context is done (requestId %d)", fut.requestId))
986986
}
987987
}
988988

@@ -1008,7 +1008,7 @@ func (conn *Connection) send(req Request, streamId uint64) *Future {
10081008
if req.Ctx() != nil {
10091009
select {
10101010
case <-req.Ctx().Done():
1011-
conn.cancelFuture(fut, fmt.Errorf("context is done"))
1011+
conn.cancelFuture(fut, fmt.Errorf("context is done (requestId %d)", fut.requestId))
10121012
return fut
10131013
default:
10141014
}

example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func ExamplePingRequest_Context() {
166166
fmt.Println("Ping Error", err)
167167
// Output:
168168
// Ping Resp data []
169-
// Ping Error context is done
169+
// Ping Error context is done (requestId 3)
170170
}
171171

172172
func ExampleSelectRequest() {

tarantool_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2731,7 +2731,7 @@ func TestClientRequestObjectsWithPassedCanceledContext(t *testing.T) {
27312731
req := NewPingRequest().Context(ctx)
27322732
cancel()
27332733
resp, err := conn.Do(req).Get()
2734-
if err.Error() != "context is done" {
2734+
if !strings.HasPrefix(err.Error(), "context is done") {
27352735
t.Fatalf("Failed to catch an error from done context")
27362736
}
27372737
if resp != nil {
@@ -2802,7 +2802,7 @@ func TestClientRequestObjectsWithContext(t *testing.T) {
28022802
if err == nil {
28032803
t.Fatalf("caught nil error")
28042804
}
2805-
if err.Error() != "context is done" {
2805+
if !strings.HasPrefix(err.Error(), "context is done") {
28062806
t.Fatalf("wrong error caught: %v", err)
28072807
}
28082808
}
@@ -3295,7 +3295,7 @@ func TestClientIdRequestObjectWithPassedCanceledContext(t *testing.T) {
32953295
resp, err := conn.Do(req).Get()
32963296
require.Nilf(t, resp, "Response is empty")
32973297
require.NotNilf(t, err, "Error is not empty")
3298-
require.Equal(t, err.Error(), "context is done")
3298+
require.ErrorContains(t, err, "context is done")
32993299
}
33003300

33013301
func TestConnectionProtocolInfoUnsupported(t *testing.T) {

0 commit comments

Comments
 (0)