Skip to content

Commit 9a9e994

Browse files
dszakallasDávid Szakállas
authored andcommitted
fix: a possibility of crash being not reported
1 parent 1c4b043 commit 9a9e994

File tree

7 files changed

+74
-51
lines changed

7 files changed

+74
-51
lines changed

lib/agent/tracer/cache.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Cache.prototype.flushExpiredChildren = function (path, until) {
141141
return flushed
142142
}
143143

144+
Cache.MAX_TIMESTAMP = 8640000000000000
145+
144146
module.exports = Cache
145147
module.exports.create = function (options) {
146148
return new Cache(options)

lib/agent/tracer/cache.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ describe('Cache', function () {
195195
cache.flushExpiredChildren([])
196196
expect(cache.get([])).to.have.members([])
197197
})
198+
199+
it('path should be expired if we flush with a high enough limit', function () {
200+
var cache = new Cache(options)
201+
var event = { type: 'sr' }
202+
cache.merge(['comm-id'], [event], options.mustCollectSeverity)
203+
cache.lock(['comm-id'])
204+
cache.flushExpiredChildren([], Cache.MAX_TIMESTAMP)
205+
expect(cache.get([])).to.have.members([])
206+
})
198207
it('path should not be expired', function () {
199208
var cache = new Cache(options)
200209
var event = { type: 'sr' }

lib/agent/tracer/collector.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,17 @@ Collector.prototype.clientRecv = function (payload, duffelBag, briefcase) {
131131
}
132132
}
133133

134-
Collector.prototype.sample = function () {
135-
var content = this.cache.flushExpiredChildren([])
134+
Collector.prototype.sample = function (until) {
135+
var content = this.cache.flushExpiredChildren([], until)
136136
if (content.length) {
137137
this.sampler.add(content)
138138
}
139139
}
140140

141+
Collector.prototype.sampleAll = function () {
142+
this.sample(Cache.MAX_TIMESTAMP)
143+
}
144+
141145
Collector.prototype.flush = function () {
142146
var buffers = this.sampler.flush()
143147
var duplicates = new Set()

lib/agent/tracer/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Tracer.prototype.sample = function () {
4444
this.collector.sample()
4545
}
4646

47+
Tracer.prototype.sampleAll = function () {
48+
this.collector.sampleAll()
49+
}
50+
4751
Tracer.prototype.send = function (isSync, callback) {
4852
callback = callback || function () {}
4953
var events = this.collector.flush()

lib/instrumentations/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ module.exports.create = function (options) {
151151
shimmer.wrap(process, '_fatalException', function (original) {
152152
return function (error) {
153153
agent.tracer.collector.systemError(error)
154+
agent.tracer.sampleAll()
154155
var sync = true
155156
agent.tracer.send(sync)
156157
return original.apply(this, arguments)

test/e2e/crash/index.spec.js

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
11
'use strict'
2-
// 'use strict'
3-
//
4-
// var express = require('express')
5-
// var bodyParser = require('body-parser')
6-
// var test = require('tape')
7-
// var spawnSync = require('spawn-sync')
8-
// var defaultsDeep = require('lodash').defaultsDeep
9-
// var path = require('path')
10-
// // var semver = require('semver')
11-
//
12-
// var TRACE_API_KEY = 'headers.payload.signature'
13-
// var TRACE_SERVICE_NAME = 'service-name'
14-
// var TEST_WEB_SERVER_PORT = process.env.TEST_WEBSERVER_PORT || 44332
15-
// var TEST_TIMEOUT = 10000
16-
//
17-
// var env = {
18-
// TRACE_API_KEY: TRACE_API_KEY,
19-
// TRACE_SERVICE_NAME: TRACE_SERVICE_NAME,
20-
// TRACE_COLLECT_INTERVAL: 100,
21-
// TRACE_UPDATE_INTERVAL: 100000,
22-
// TRACE_COLLECTOR_API_URL: 'http://127.0.0.1:' + TEST_WEB_SERVER_PORT
23-
// }
24-
//
25-
// test('should report crash', {
26-
// timeout: TEST_TIMEOUT,
27-
// skip: true // !semver.satisfies(process.version, '>= 6')
28-
// }, function (t) {
29-
// var app = express()
30-
// app.use(bodyParser.json())
31-
// app.post('/transaction-events', function (req, res) {
32-
// var event = req.body.e.find(function (e) {
33-
// return e.t === 'err' && e.d.t === 'system-error'
34-
// })
35-
// t.ok(event != null, 'Error event exists')
36-
// t.end()
37-
// process.exit(0)
38-
// })
39-
// app.listen(TEST_WEB_SERVER_PORT, function (err) {
40-
// t.error(err, 'server starts listening at ' + TEST_WEB_SERVER_PORT)
41-
//
42-
// spawnSync('node', [path.join(__dirname, 'testee.js')], {
43-
//
44-
// env: defaultsDeep({}, env, process.env)
45-
// })
46-
// })
47-
// })
2+
3+
var express = require('express')
4+
var bodyParser = require('body-parser')
5+
var test = require('tape')
6+
var spawnSync = require('spawn-sync')
7+
var defaultsDeep = require('lodash').defaultsDeep
8+
var path = require('path')
9+
var find = require('lodash.find')
10+
// var semver = require('semver')
11+
12+
var TRACE_API_KEY = 'headers.payload.signature'
13+
var TRACE_SERVICE_NAME = 'service-name'
14+
var TEST_WEB_SERVER_PORT = process.env.TEST_WEBSERVER_PORT || 44333 + Math.trunc(Math.random() * 100)
15+
var TEST_TIMEOUT = 10000
16+
17+
var env = {
18+
TRACE_API_KEY: TRACE_API_KEY,
19+
TRACE_SERVICE_NAME: TRACE_SERVICE_NAME,
20+
TRACE_COLLECT_INTERVAL: 100,
21+
TRACE_UPDATE_INTERVAL: 100000,
22+
TRACE_COLLECTOR_API_URL: 'http://127.0.0.1:' + TEST_WEB_SERVER_PORT
23+
}
24+
25+
test('should report crash', {
26+
timeout: TEST_TIMEOUT
27+
}, function (t) {
28+
var server
29+
var app = express()
30+
app.use(bodyParser.json())
31+
app.post('/transaction-events', function (req, res) {
32+
try {
33+
t.ok(req.body.e, 'Events are reported')
34+
console.log(req.body.e)
35+
var event = find(req.body.e, function (e) {
36+
return e.t === 'err' && e.d.t === 'system-error'
37+
})
38+
t.ok(event != null, 'Error event exists')
39+
t.end()
40+
} finally {
41+
server.close()
42+
}
43+
})
44+
server = app.listen(TEST_WEB_SERVER_PORT, function (err) {
45+
t.error(err, 'server starts listening at ' + TEST_WEB_SERVER_PORT)
46+
47+
spawnSync('node', [path.join(__dirname, 'testee.js')], {
48+
stdio: [0, 1, 2],
49+
env: defaultsDeep({}, env, process.env)
50+
})
51+
})
52+
})

test/e2e/utils/test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ function childProcessTest (name_, opts_, cb_, args, fn) {
4545

4646
function test (name_, opts_, cb_) {
4747
var args = getTestArgs(name_, opts_, cb_)
48-
if (args.skip) {
48+
if (args.opts.skip) {
4949
test.skip(name_, opts_, cb_)
50-
} else if (args.only) {
51-
test.only(name_, opts_, cb_)
5250
} else if (process.env.TEST_ISOLATE === 'child-process') {
5351
childProcessTest(name_ + ' (child process running in ' + process.pid + ')', opts_, cb_, args, tape.only)
5452
} else {

0 commit comments

Comments
 (0)