Skip to content

Commit

Permalink
otelhttp: nil check wrappedBody.Close
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Apr 6, 2022
1 parent 8cf7954 commit 75693e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion instrumentation/net/http/otelhttp/transport.go
Expand Up @@ -186,5 +186,8 @@ func (wb *wrappedBody) Read(b []byte) (int, error) {

func (wb *wrappedBody) Close() error {
wb.span.End()
return wb.body.Close()
if wb.body != nil {
return wb.body.Close()
}
return nil
}
4 changes: 4 additions & 0 deletions instrumentation/net/http/otelhttp/transport_test.go
Expand Up @@ -279,6 +279,10 @@ func TestWrappedBodyClose(t *testing.T) {
wb := &wrappedBody{span: trace.Span(s), body: readCloser{}}
assert.NoError(t, wb.Close())
s.assert(t, true, nil, codes.Unset, "")

var body io.ReadCloser
wb2 := newWrappedBody(s, body)
assert.NoError(t, wb2.Close())
}

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

0 comments on commit 75693e7

Please sign in to comment.