stdin with couchdb #2820

Closed
hockeytim11 opened this Issue Feb 23, 2012 · 7 comments

Comments

Projects
None yet
5 participants

I am attempting to run nodejs as an os daemon in couchdb on windows. The os daemon api uses stdio to communicate with the launched node process. The code below works with node version 0.5.7 but has since stopped working in recent versions.

The code works fine on linux.

here is the os daemon api (which includes a nodejs daemon example near the bottom)
http://davispj.com/2010/09/26/new-couchdb-externals-api.html

I have modified the example to use the resume() function rather than openStdin() and neither the data or end events are being hit.

I am using couchdb version 1.1.1 and node version 0.6.11

and the code:

    var http = require('http');
    var sys = require('sys');

    // Send a log message to be included in CouchDB's
    // log files.

    var log = function(mesg) {
      console.log(JSON.stringify(["log", mesg]));
    }

    // We use stdin in a couple ways. First, we
    // listen for data that will be the requested
    // port information. We also listen for it
    // to close which indicates that CouchDB has
    // exited and that means its time for us to
    // exit as well.

    log("readable: " + process.stdin.readable);
    process.stdin.resume();

    process.stdin.on('data', function(d) {
      console.log(d.toString());
      log("listening");
    });

    process.stdin.on('end', function () {
        log("end");
      process.exit(0);
    });

    process.stdin.on('error',function(exception){
        console.log(exception);
    });

    // Send the request for the port to listen on.

    console.log(JSON.stringify(["get", "node_hello", "port"]));
    log("starting test");
    log("readable: " + process.stdin.readable);

ssuda commented Feb 24, 2012

This is similar to #2792

I should also mention that the log messages do work and can be seen in couchdb.

@ssuda Maybe, but I don't think so. We can do some diagnosing.

@hockeytim11 Try logging process.argv and require('tty').isatty(0).

@TooTallNate Here are the log messages in couchdb.

[info] [<0.99.0>] Daemon "test" :: argv: node,C:\CouchDB\bin\test.js
[info] [<0.99.0>] Daemon "test" :: isatty: false

@ssuda ^ So that proves that it's not related to #2792, since that issue is when node is invoked with no additional arguments, to get into the REPL.

@hockeytim11 If you want to really nail it down, checkout the node repo and git bisect in between 0.5.7 and 0.6.11 to see exactly which commit broke it. That would be the most helpful to help us understand.

@hockeytim11 did you had the chance to follow @TooTallNate suggestion (git bisect in between 0.5.7 and 0.6.11 to see exactly which commit broke it)?

I'm going to close this, unless someone is still having an issue on a reasonable version of node

tjfontaine closed this Dec 30, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment