Skip to content

Commit c00d276

Browse files
committed
a few fixes
- fix 'assert' usage for node 8.6 - always destroy the intakeReq on error, I observed (in node 8.6 at least) a intakeReq "timeout" after both a "close" and "error" event. I guess those don't clear the socket timeout. I'm not sure if this is tied to keep-alive agent. In any case, if there is an error, let's make sure to recycle that socket. - gzipStream.pause() on premature response from APM server just in the rare/unlikely case reading the response body and destroying takes a long while. This is a nod to elastic#32 but I'm not sure it is necessary. Doesn't hurt.
1 parent f04a835 commit c00d276

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const assert = require('assert').strict
3+
const assert = require('assert')
44
const crypto = require('crypto')
55
const http = require('http')
66
const https = require('https')
@@ -645,14 +645,12 @@ function getChoppedStreamHandler (client, onerror) {
645645
// There was an error: clean up resources.
646646
//
647647
// Note that in Node v8, destroying the gzip stream results in it
648-
// erroring with the following. No harm, however.
648+
// emitting an "error" event as follows. No harm, however.
649649
// Error: gzip stream error: zlib binding closed
650650
// at Gzip._transform (zlib.js:369:15)
651651
// ...
652652
destroyStream(gzipStream)
653-
if (!completedFromPart['intakeReq']) { // eslint-disable-line dot-notation
654-
intakeReq.destroy()
655-
}
653+
intakeReq.destroy()
656654
}
657655

658656
client.sent = client._received
@@ -752,6 +750,10 @@ function getChoppedStreamHandler (client, onerror) {
752750
if (intakeRes.statusCode === SUCCESS_STATUS_CODE) {
753751
err = new Error(`premature apm-server response with statusCode=${intakeRes.statusCode}`)
754752
}
753+
// There is no point (though no harm) in sending more data to the APM
754+
// server. In case reading the error response body takes a while, pause
755+
// the gzip stream until it is destroyed in `completePart()`.
756+
gzipStream.pause()
755757
}
756758

757759
// Handle events on the intake response.

0 commit comments

Comments
 (0)