Skip to content

Commit

Permalink
Avoid work for already-canceled requests (#213)
Browse files Browse the repository at this point in the history
This is consistent with gRPC behavior for unary exporters, as with for
HTTP exporters.
It also helps us test with realistic conditions in the new integration
test of #210.

https://grpc.io/docs/guides/deadlines/ explains why the default behavior
is the way it is for unary gRPC. This is also the case for Golang's
net/http client, which is used for the OTLP/HTTP exporter. Therefore, it
seems the right thing to do for Arrow as well. Further, if we were to
support extending the deadline on purpose, it would belong in the
exporterhelper code (IMO).

---------

Co-authored-by: Laurent Quérel <[email protected]>
  • Loading branch information
jmacd and lquerel authored Jun 5, 2024
1 parent b0816c6 commit 03212ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ func (e *Exporter) runArrowStream(ctx context.Context, dc doneCancel, state *str
//
// consumer should fall back to standard OTLP, (true, nil)
func (e *Exporter) SendAndWait(ctx context.Context, data any) (bool, error) {
// If the incoming context is already canceled, return the
// same error condition a unary gRPC or HTTP exporter would do.
select {
case <-ctx.Done():
return false, status.Errorf(codes.Canceled, "context done before send: %v", ctx.Err())
default:
}

errCh := make(chan error, 1)

// Note that if the OTLP exporter's gRPC Headers field was
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ func TestArrowExporterTimeout(t *testing.T) {
require.True(t, is, "is a gRPC status")
require.Equal(t, codes.Canceled, stat.Code())

// Repeat the request, will get immediate timeout.
sent, err = tc.exporter.SendAndWait(ctx, twoTraces)
stat, is = status.FromError(err)
require.True(t, is, "is a gRPC status error: %v", err)
require.Equal(t, "context done before send: context canceled", stat.Message())
require.Equal(t, codes.Canceled, stat.Code())

require.NoError(t, tc.exporter.Shutdown(ctx))
})
}
Expand Down

0 comments on commit 03212ef

Please sign in to comment.