Skip to content

Commit

Permalink
api: more informative request canceling
Browse files Browse the repository at this point in the history
Log the probable reason for unexpected requestId.
Add requestId info to context done error message.
  • Loading branch information
nurzhan-saktaganov committed Sep 19, 2024
1 parent 0ccdee2 commit 06ed7f8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- Implemented stringer methods for pool.Role (#405).

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

### Fixed

Expand Down
8 changes: 4 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
conn.Addr(), err)
case LogUnexpectedResultId:
header := v[0].(Header)
log.Printf("tarantool: connection %s got unexpected resultId (%d) in response",
log.Printf("tarantool: connection %s got unexpected resultId (%d) in response (probably canceled request)",

Check failure on line 103 in connection.go

View workflow job for this annotation

GitHub Actions / golangci-lint

the line is 115 characters long, which exceeds the maximum of 100 characters. (lll)
conn.Addr(), header.RequestId)
case LogWatchEventReadFailed:
err := v[0].(error)
Expand Down Expand Up @@ -940,7 +940,7 @@ func (conn *Connection) newFuture(req Request) (fut *Future) {
if ctx != nil {
select {
case <-ctx.Done():
fut.SetError(fmt.Errorf("context is done"))
fut.SetError(fmt.Errorf("context is done (requestId %d)", fut.requestId))
shard.rmut.Unlock()
return
default:
Expand Down Expand Up @@ -982,7 +982,7 @@ func (conn *Connection) contextWatchdog(fut *Future, ctx context.Context) {
case <-fut.done:
return
default:
conn.cancelFuture(fut, fmt.Errorf("context is done"))
conn.cancelFuture(fut, fmt.Errorf("context is done (requestId %d)", fut.requestId))
}
}

Expand All @@ -1008,7 +1008,7 @@ func (conn *Connection) send(req Request, streamId uint64) *Future {
if req.Ctx() != nil {
select {
case <-req.Ctx().Done():
conn.cancelFuture(fut, fmt.Errorf("context is done"))
conn.cancelFuture(fut, fmt.Errorf("context is done (requestId %d)", fut.requestId))
return fut
default:
}
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func ExamplePingRequest_Context() {
fmt.Println("Ping Error", err)
// Output:
// Ping Resp data []
// Ping Error context is done
// Ping Error context is done (requestId 3)
}

func ExampleSelectRequest() {
Expand Down
6 changes: 3 additions & 3 deletions tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2731,7 +2731,7 @@ func TestClientRequestObjectsWithPassedCanceledContext(t *testing.T) {
req := NewPingRequest().Context(ctx)
cancel()
resp, err := conn.Do(req).Get()
if err.Error() != "context is done" {
if !strings.HasPrefix(err.Error(), "context is done") {
t.Fatalf("Failed to catch an error from done context")
}
if resp != nil {
Expand Down Expand Up @@ -2802,7 +2802,7 @@ func TestClientRequestObjectsWithContext(t *testing.T) {
if err == nil {
t.Fatalf("caught nil error")
}
if err.Error() != "context is done" {
if !strings.HasPrefix(err.Error(), "context is done") {
t.Fatalf("wrong error caught: %v", err)
}
}
Expand Down Expand Up @@ -3295,7 +3295,7 @@ func TestClientIdRequestObjectWithPassedCanceledContext(t *testing.T) {
resp, err := conn.Do(req).Get()
require.Nilf(t, resp, "Response is empty")
require.NotNilf(t, err, "Error is not empty")
require.Equal(t, err.Error(), "context is done")
require.ErrorContains(t, err, "context is done")
}

func TestConnectionProtocolInfoUnsupported(t *testing.T) {
Expand Down

0 comments on commit 06ed7f8

Please sign in to comment.