├── .gitignore ├── Readme.md ├── herd.js ├── package.json ├── server.js └── throng.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # 100 Ways to Die 2 | 3 | An exploration into zero-downtime node servers. The goal is to test the various ways a node server can die and figure out which node modules or techniques can help keep our servers up. 4 | 5 | ## API Endpoints 6 | 7 | ```http 8 | GET /uncaught/sync - throw an uncaught exception synchronously 9 | GET /uncaught/async - throw an uncaught exception asynchronously 10 | GET /process/exit - call process.exit() 11 | GET /      - check if the server is still running 12 | ``` 13 | 14 | ## License 15 | 16 | MIT 17 | -------------------------------------------------------------------------------- /herd.js: -------------------------------------------------------------------------------- 1 | // TODO 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "100-ways-to-die", 3 | "version": "1.0.0", 4 | "description": "all the ways you can kill a node server", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node --harmony throng.js" 9 | }, 10 | "author": "Matthew Mueller", 11 | "license": "MIT", 12 | "dependencies": { 13 | "roo": "0.2.0", 14 | "throng": "^1.0.0" 15 | }, 16 | "engine": { 17 | "node": "0.12" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module Dependencies 3 | */ 4 | 5 | var roo = module.exports = require('roo')(__dirname); 6 | 7 | /** 8 | * Die 9 | */ 10 | 11 | roo.get('/uncaught/sync', function *(next) { 12 | throw new Error('sync error'); 13 | }); 14 | 15 | roo.get('/uncaught/async', function *(next) { 16 | console.log('handling!'); 17 | process.nextTick(function() { 18 | throw new Error('async error'); 19 | }); 20 | }); 21 | 22 | roo.get('/process/exit', function *(next) { 23 | process.exit(); 24 | }) 25 | 26 | roo.get('/', function *(next) { 27 | console.log('getting /'); 28 | this.body = 'I\'m alive!'; 29 | }) 30 | -------------------------------------------------------------------------------- /throng.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module Dependencies 3 | */ 4 | 5 | var server = require('./server'); 6 | var port = process.env.PORT || 7000; 7 | var throng = require('throng'); 8 | 9 | /** 10 | * Throng 11 | */ 12 | 13 | throng(start, { lifetime: Infinity, workers: 1 }); 14 | 15 | /** 16 | * Start 17 | */ 18 | 19 | function start() { 20 | server.listen(port, function() { 21 | var addr = this.address(); 22 | console.log('listening on [%s]:%d', addr.address, addr.port); 23 | }) 24 | } 25 | --------------------------------------------------------------------------------