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

fix(otlp-exporter-base): fix unhandled error when writing to destroyed http request #5163

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ All notable changes to experimental packages in this project will be documented
### :bug: (Bug Fix)

* fix(instrumentation-http): Fix the `OTEL_SEMCONV_STABILITY_OPT_IN` variable check. Using `of` instead of `in` [#5137](/~https://github.com/open-telemetry/opentelemetry-js/pull/5137)

* fix(instrumentation-http): drop url.parse in favor of URL constructor [#5091](/~https://github.com/open-telemetry/opentelemetry-js/pull/5091) @pichlermarc
* fixes a bug where using cyrillic characters in a client request string URL would throw an exception, whereas an un-instrumented client would accept the same input without throwing an exception
* fix(otlp-exporter-base): fix unhandled error when writing to destroyed http request [#5163](/~https://github.com/open-telemetry/opentelemetry-js/pull/5163) @pichlermarc

### :books: (Refine Doc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function sendWithHttp(
});
}

function compressAndSend(
export function compressAndSend(
req: http.ClientRequest,
compression: 'gzip' | 'none',
data: Uint8Array,
Expand All @@ -127,7 +127,7 @@ function compressAndSend(
.on('error', onError);
}

dataStream.pipe(req);
dataStream.pipe(req).on('error', onError);
}

function readableFromUint8Array(buff: string | Uint8Array): Readable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as http from 'http';
import * as assert from 'assert';
import { compressAndSend } from '../../src/platform/node/http-transport-utils';

describe('compressAndSend', function () {
it('compressAndSend on destroyed request should handle error', function (done) {
const request = http.request({});
request.destroy();
compressAndSend(request, 'gzip', Buffer.from([1, 2, 3]), error => {
try {
assert.match(error.message, /socket hang up/);
done();
} catch (e) {
done(e);
}
});
});
});
Loading