-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (31 loc) · 1.03 KB
/
server.js
File metadata and controls
39 lines (31 loc) · 1.03 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
'use strict';
const express = require('express');
const fs = require('fs');
const app = express();
const PORT = 3000;
const OOM_MARKER = '/data/oom-marker';
if (!fs.existsSync(OOM_MARKER)) {
console.log('[run-1] First run — will OOM in 5 seconds');
app.get('/', (req, res) => {
res.send('Running — will OOM soon');
});
app.listen(PORT, '0.0.0.0', () => {
console.log(`[run-1] Server running on port ${PORT}`);
});
setTimeout(() => {
console.log('[run-1] Writing marker and allocating memory until OOM kill...');
fs.writeFileSync(OOM_MARKER, new Date().toISOString());
const chunks = [];
while (true) {
chunks.push(Buffer.alloc(10 * 1024 * 1024, 'x'));
}
}, 5000);
} else {
console.log('[run-2] Restarted after OOM, running normally');
app.get('/', (req, res) => {
res.send('OK — running after OOM recovery');
});
app.listen(PORT, '0.0.0.0', () => {
console.log(`[run-2] Server running on port ${PORT}`);
});
}