Created
June 26, 2013 22:38
-
-
Save dgrelaud/5872380 to your computer and use it in GitHub Desktop.
Small test case to reproduce the bug "uv__server_io: Assertion `events == 1' failed"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Platform | |
| ---------------------------------- | |
| Ubuntu 12.04 LTS 64bits | |
| How it works? | |
| ---------------------------------- | |
| 1. Execute a simple server: | |
| >> node test.js | |
| 2. Execute a server with 2 workers: | |
| >> node test.js --clusters 2 | |
| 3. Execute a server with 2 workers and call require('child_process').exec | |
| >> node test.js --clusters 2 --exec | |
| What is the problem? | |
| -------------------- | |
| With Node v0.10.12, the command 3 will generate the error "node: ../deps/uv/src/unix/stream.c:494: uv__server_io: Assertion `events == 1' failed" | |
| With Node v0.8.25, it works. | |
| */ | |
| var fs = require('fs'); | |
| var path = require('path'); | |
| var cluster = require('cluster'); | |
| var numCPUs = require('os').cpus().length; | |
| var rootPath = process.cwd(); | |
| var exec = require('child_process').exec; | |
| var net = require('net'); | |
| var nbClusters = 0; | |
| var simpleExec = false; | |
| var args = process.argv.slice(2); | |
| //parsing arguments | |
| while(args.length > 0 ){ | |
| var _argument = args.shift(); | |
| switch(_argument){ | |
| case '--clusters': | |
| nbClusters = args.shift(); | |
| break; | |
| case '--exec': | |
| simpleExec = true; | |
| break; | |
| default: | |
| console.log('Error while parsing command '+_argument); | |
| } | |
| } | |
| //debug info | |
| if(cluster.isMaster===true || nbClusters===0){ | |
| console.log('-- Application started'); | |
| if(nbClusters>0){ | |
| console.log(' Number of workers: '+nbClusters); | |
| } | |
| } | |
| //start clusters | |
| if(nbClusters > 0 && cluster.isMaster){ | |
| //Fork | |
| for (var i = 0; i < nbClusters ; i++) { | |
| cluster.fork(); | |
| } | |
| cluster.on('exit', function(worker, code, signal) { | |
| var _exitCode = worker.process.exitCode; | |
| console.log('worker ' + worker.process.pid + ' died ('+_exitCode+'). restarting...'); | |
| cluster.fork(); | |
| }); | |
| } | |
| //start a server | |
| if (!cluster.isMaster || nbClusters === 0){ | |
| var server = net.createServer(function(c) { //'connection' listener | |
| console.log('server connected'); | |
| c.on('end', function() { | |
| console.log('server disconnected'); | |
| }); | |
| c.write('hello\r\n'); | |
| c.pipe(c); | |
| }); | |
| server.listen(8124, function() { //'listening' listener | |
| console.log('server bound'); | |
| }); | |
| } | |
| //try to launch only one exec | |
| if (simpleExec === true){ | |
| exec('zip --help', function(error, stdout, stderr){ | |
| console.log('exec 1 done'); | |
| console.log(error); | |
| console.log(stderr); | |
| }); | |
| } | |
| //stay alive | |
| setInterval(function(){ | |
| console.log('process '+process.pid+' is working'); | |
| },800); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment