Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Node exit after new SerialPort() #59

Closed
nosteve opened this Issue · 13 comments

7 participants

@nosteve

A bit stumped, node script is causing exit without error on Windows, even when trying to capture unhandled exceptions using the "process.on" trick. Narrowed this behavior down to when I create a new SerialPort object.

System is Windows 7 Pro x64, using latest Node 0.8.3. Built libs using VS Express 2010.

Script works on Mac using same libraries without issue. Removing the new SerialPort() line resolves the issue, script works fine otherwise.

Here is sample program to repro and debug info. I'm not sure where else to look - maybe it's a bad compile, or some kind of 64-bit issue? It seems like the OS might be killing it but I don't see anything in Event Viewer (maybe I need to turn on more options in there?) Any troubleshooting help appreciated.

repro:

var connect = require('connect');
var SerialPort = require('serialport').SerialPort;
var argv = process.argv;

process.on('uncaughtException', function(err) {
  console.log(err);
});

var serialPort = new SerialPort();

connect.createServer(
    connect.static(__dirname)
).listen(argv[2] || 8082);

debug:

C:\Users\Steve\src\glomo>node debug wtf.js
< debugger listening on port 5858
connecting... ok
break in C:\Users\Steve\src\glomo\wtf.js:1
  1 var connect = require('connect');
  2 var SerialPort = require('serialport').SerialPort;
  3 var argv = process.argv;
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:2
  1 var connect = require('connect');
  2 var SerialPort = require('serialport').SerialPort;
  3 var argv = process.argv;
  4
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:2
  1 var connect = require('connect');
  2 var SerialPort = require('serialport').SerialPort;
  3 var argv = process.argv;
  4
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:3
  1 var connect = require('connect');
  2 var SerialPort = require('serialport').SerialPort;
  3 var argv = process.argv;
  4
  5 process.on('uncaughtException', function(err) {
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:5
  3 var argv = process.argv;
  4
  5 process.on('uncaughtException', function(err) {
  6   console.log(err);
  7 });
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:9
  7 });
  8
  9 var serialPort = new SerialPort();
 10
 11 connect.createServer(
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:12
 10
 11 connect.createServer(
 12     connect.static(__dirname)
 13 ).listen(argv[2] || 8082);
 14
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:11
  9 var serialPort = new SerialPort();
 10
 11 connect.createServer(
 12     connect.static(__dirname)
 13 ).listen(argv[2] || 8082);
debug> n
break in C:\Users\Steve\src\glomo\wtf.js:16
 14
 15
 16 });
debug> n
break in module.js:450
 448   var args = [self.exports, require, self, filename, dirname];
 449   return compiledWrapper.apply(self.exports, args);
 450 };
 451
 452
debug> n
break in module.js:468
 466   var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
 467   module._compile(stripBOM(content), filename);
 468 };
 469
 470
debug> n
break in module.js:357
 355   if (!Module._extensions[extension]) extension = '.js';
 356   Module._extensions[extension](this, filename);
 357   this.loaded = true;
 358 };
 359
debug> n
break in module.js:358
 356   Module._extensions[extension](this, filename);
 357   this.loaded = true;
 358 };
 359
 360
debug> n
break in module.js:313
 311   try {
 312     module.load(filename);
 313     hadException = false;
 314   } finally {
 315     if (hadException) {
debug> n
break in module.js:315
 313     hadException = false;
 314   } finally {
 315     if (hadException) {
 316       delete Module._cache[filename];
 317     }
debug> n
break in module.js:320
 318   }
 319
 320   return module.exports;
 321 };
 322
debug> n
break in module.js:321
 319
 320   return module.exports;
 321 };
 322
 323 Module._resolveFilename = function(request, parent) {
debug> n
break in module.js:493
 491   // Load the main module--the command line argument.
 492   Module._load(process.argv[1], null, true);
 493 };
 494
 495 Module._initPaths = function() {
debug> n
break in timers.js:106
 104             process.emit('uncaughtException', e);
 105           }
 106           if (first.domain) first.domain.exit();
 107         }
 108       }
debug> n
break in timers.js:78
  76
  77       var first;
  78       while (first = L.peek(list)) {
  79         var diff = now - first._idleStart;
  80         if (diff + 1 < msecs) {
debug> n
break in timers.js:110
 108       }
 109
 110       debug(msecs + ' list empty');
 111       assert(L.isEmpty(list));
 112       list.close();
debug> n
break in timers.js:111
 109
 110       debug(msecs + ' list empty');
 111       assert(L.isEmpty(list));
 112       list.close();
 113       delete lists[msecs];
debug> n
break in timers.js:112
 110       debug(msecs + ' list empty');
 111       assert(L.isEmpty(list));
 112       list.close();
 113       delete lists[msecs];
 114     };
debug> n
break in timers.js:114
 112       list.close();
 113       delete lists[msecs];
 114     };
 115   }
 116
debug> n
program terminated
debug>

@joeferner
Collaborator

Are you passing any arguments to the constructor of SerialPort in your example you are not?

@nosteve

No actually I've gotten away with using the defaults (9600,N,8,1) so far using serialport on Linux and Mac - but yeah I probably should have tried messing with those. Think that's causing the issue?

@jankolkmeier

Same Issue here, did you get it to work, nosteve?

@joeferner
Collaborator

@nosteve You at least need to pass in the port name ie "COM1". Try running serialport/bin/serialportList.js and see if that works.

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("COM1");
@jankolkmeier

Hey @joeferner I also did the serialportList.cmd, which returns a correct list. My port is "COM10" (I used this before). The issue I am observing is the one nosteve already described. Node.js exits the process shortly after the SerialPort() constructor is used. The following script works as expected, returning "foo" directly, then "bar", then exits:

var SerialPort = require("serialport").SerialPort
//var serialPort = new SerialPort("COM10");

setTimeout(function() {
  console.log("bar");
}, 3000);

console.log("foo");

while this one just returns "foo" and then exits without further notice and without ever returning "bar":

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("COM10");

setTimeout(function() {
  console.log("bar");
}, 3000);

console.log("foo");

I'm using node 0.6.19. Windows 7 64bit. Works fine for me under GNU/Linux.

@joeferner
Collaborator

If you don't mind can you pull the latest code and try again. We had some incorrect logic dealing with windows, it should be fixed now.

@kmitchel

Fix worked for me. Going crazy trying to figure out what I was doing wrong. Thanx!

@jankolkmeier

Worked for me, too. Thanks!

@joeferner joeferner closed this
@nosteve
@JayBeavers
Collaborator

Is there an ETA for when this will appear on npm? This is a fatal issue for Windows users of this library.

@voodootikigod

Published 1.0.2 today.

@JayBeavers
Collaborator

Thank you. Tested and fix is working great.

@micred

I have this problem on Windows with serialport 1.3.0 and ruby-1.9.3-p484.
Any help?
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.