This repository was archived by the owner on Jun 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathfatalerror.js
More file actions
43 lines (37 loc) · 1.24 KB
/
fatalerror.js
File metadata and controls
43 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Example - generation of Nodereport on fatal error (Javascript heap OOM)
require('nodereport').setEvents('fatalerror');
var http = require('http');
var count = 0;
function my_listener(request, response) {
switch(count++) {
case 0:
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('\nRunning NodeReport fatal error demo... refresh page to trigger excessive memory usage (application will terminate)');
response.end();
break;
case 1:
console.log('heap_oom.js: allocating excessive Javascript heap memory....');
var list = [];
while (true) {
list.push(new MyRecord());
}
/*eslint-disable no-unreachable */
response.end();
break;
/*eslint-enable no-unreachable */
}
}
function MyRecord() {
this.name = 'foo';
this.id = 128;
this.account = 98454324;
}
var http_server = http.createServer(my_listener);
http_server.listen(8080);
console.log('fatalerror.js: Node running');
console.log('fatalerror.js: Note: heap default is 1.4Gb, use --max-old-space-size=<size in Mb> to change');
console.log('fatalerror.js: Go to http://<machine>:8080/ or http://localhost:8080/');
setTimeout(function(){
console.log('fatalerror.js: timeout expired, exiting.');
process.exit(0);
}, 60000);