Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node exit after new SerialPort() #59

Closed
nosteve opened this issue Jul 24, 2012 · 13 comments
Closed

Node exit after new SerialPort() #59

nosteve opened this issue Jul 24, 2012 · 13 comments

Comments

@nosteve
Copy link

nosteve commented Jul 24, 2012

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
Copy link
Contributor

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

@nosteve
Copy link
Author

nosteve commented Jul 24, 2012

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
Copy link

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

@joeferner
Copy link
Contributor

@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
Copy link

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
Copy link
Contributor

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
Copy link

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

@jankolkmeier
Copy link

Worked for me, too. Thanks!

@nosteve
Copy link
Author

nosteve commented Jul 25, 2012

Traveling atm but sounds like this will fix my problem as well. I was indeed passing the serial port (COM4, and tried .\COM4 too) despite my bad repro code :P The others are describing the same issue and sounds like your change fixed it - so thanks for the quick turnaround!

This transmission may contain information that is privileged, confidential, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format.

@JayBeavers
Copy link
Collaborator

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

@voodootikigod
Copy link
Collaborator

Published 1.0.2 today.

@JayBeavers
Copy link
Collaborator

Thank you. Tested and fix is working great.

@micred
Copy link

micred commented Mar 12, 2014

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

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

7 participants