Skip to content

Commit 9e4d36c

Browse files
authored
fix(otlp-exporter-base): fix unhandled error when writing to destroyed http request (open-telemetry#5163)
1 parent d3630af commit 9e4d36c

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

experimental/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ All notable changes to experimental packages in this project will be documented
5252
### :bug: (Bug Fix)
5353

5454
* 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)
55-
5655
* fix(instrumentation-http): drop url.parse in favor of URL constructor [#5091](https://github.com/open-telemetry/opentelemetry-js/pull/5091) @pichlermarc
5756
* 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
57+
* fix(otlp-exporter-base): fix unhandled error when writing to destroyed http request [#5163](https://github.com/open-telemetry/opentelemetry-js/pull/5163) @pichlermarc
5858

5959
### :books: (Refine Doc)
6060

experimental/packages/otlp-exporter-base/src/platform/node/http-transport-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function sendWithHttp(
111111
});
112112
}
113113

114-
function compressAndSend(
114+
export function compressAndSend(
115115
req: http.ClientRequest,
116116
compression: 'gzip' | 'none',
117117
data: Uint8Array,
@@ -127,7 +127,7 @@ function compressAndSend(
127127
.on('error', onError);
128128
}
129129

130-
dataStream.pipe(req);
130+
dataStream.pipe(req).on('error', onError);
131131
}
132132

133133
function readableFromUint8Array(buff: string | Uint8Array): Readable {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import * as http from 'http';
17+
import * as assert from 'assert';
18+
import { compressAndSend } from '../../src/platform/node/http-transport-utils';
19+
20+
describe('compressAndSend', function () {
21+
it('compressAndSend on destroyed request should handle error', function (done) {
22+
const request = http.request({});
23+
request.destroy();
24+
compressAndSend(request, 'gzip', Buffer.from([1, 2, 3]), error => {
25+
try {
26+
assert.match(error.message, /socket hang up/);
27+
done();
28+
} catch (e) {
29+
done(e);
30+
}
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)