Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelhttp: nil check wrappedBody.Close #2164

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Upgraded all dependencies on stable modules from `go.opentelemetry.io/otel` from v1.5.0 to v1.6.1. (#2134)
- Upgraded all dependencies on metric modules from `go.opentelemetry.io/otel` from v0.27.0 to v0.28.0. (#1977)

### Fixed

- otelhttp: Avoid panic by adding nil check to `wrappedBody.Close` (#2164)

## [1.5.0/0.30.0/0.1.0] - 2022-03-16

### Added
Expand Down
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
}
7 changes: 7 additions & 0 deletions instrumentation/net/http/otelhttp/transport_test.go
Expand Up @@ -281,6 +281,13 @@ func TestWrappedBodyClose(t *testing.T) {
s.assert(t, true, nil, codes.Unset, "")
}

func TestWrappedBodyClosePanic(t *testing.T) {
s := new(span)
var body io.ReadCloser
adamdecaf marked this conversation as resolved.
Show resolved Hide resolved
wb := newWrappedBody(s, body)
assert.NotPanics(t, func() { wb.Close() }, "nil body should not panic on close")
}

func TestWrappedBodyCloseError(t *testing.T) {
s := new(span)
expectedErr := errors.New("test")
Expand Down