mozilla / node-firefox

node.js modules for interacting with Firefox via the DevTools remote protocol
https://www.npmjs.org/package/firefox
Mozilla Public License 2.0
301 stars 18 forks source link

io.js and node 0.12 issues #40

Open sole opened 9 years ago

sole commented 9 years ago

I have had reports of a few people saying this project doesn't work and they cannot install apps, but none of them filed a bug report (AHEM AHEM).

Later I updated a computer and decided to go all brave and install io.js and try node-firefox. And it didn't work. I tried with the latest node which happened to be 0.12 and it didn't work either. I had to roll back to 0.10 and it did work.

Because I did all this in a hurry I didn't keep any logs and I do not know what it was exactly other than a obscure trace coming from somewhere.

If someone could take a look at this it would be really appreciated. Even if it's just to find the root of the issue.

lmorchard commented 9 years ago

So, I updated to node v0.12.2 via homebrew on OS X. Just started poking at a few modules and tests pass. I tried running a little script I've got that connects to a simulator and a device, and it worked fine to install and launch an app.

Couldn't reproduce an issue, but I'm assuming that means I'm just missing it. Do you have some steps to reproduce where you ran into this, and also maybe a copypasta of the error trace you saw?

lmorchard commented 9 years ago

FWIW, I also downloaded io.js v1.7.1 binaries for OS X, and was able to install apps to a simulator and device without error.

sole commented 9 years ago

thanks for looking into this! It was the examples in this repository: https://github.com/sole/ck-node-firefox

I should try to reproduce it but I'm busy with another thing and can't do it this week :-(

lmorchard commented 9 years ago

So, I just discovered that I can reliably make node-firefox-install-app segfault on node v0.12.2 after I hit the "Reset and enable full DevTools" button in the Developer settings on my Flame.

If I flash the device to a base image and just turn on DevTools & ADB debugging, things work fine. Once I hit that "reset & enable" button again, the segfaults return.

No idea what could cause that, but it seems like handy additional info

lmorchard commented 9 years ago

I installed segfault-handler and plugged it into the node-firefox-cli stuff I'm working on.

This is what I get:

ID 52223 received SIGSEGV for address: 0x105643000
0   segfault-handler.node               0x0000000100fc391a _ZL16segfault_handleriP9__siginfoPv + 282
1   libsystem_platform.dylib            0x00007fff8e8fcf1a _sigtramp + 26
2   ???                                 0x0000000000000000 0x0 + 0
3   node                                0x00000001003c6f80 _ZN7unibrow15Utf8DecoderBase14WriteUtf16SlowEPKhPtj + 82
4   node                                0x00000001001d9c75 _ZN2v88internal7Factory17NewStringFromUtf8ENS0_6VectorIKcEENS0_13PretenureFlagE + 347
5   node                                0x000000010011eda6 _ZN2v86String11NewFromUtf8EPNS_7IsolateEPKcNS0_13NewStringTypeEi + 194
6   node                                0x0000000100461dcc _ZN4node11StringBytes6EncodeEPN2v87IsolateEPKcmNS_8encodingE + 164
7   node                                0x0000000100445ab6 _ZN4node6Buffer11StringSliceILNS_8encodingE1EEEvRKN2v820FunctionCallbackInfoINS3_5ValueEEE + 422
8   node                                0x0000000100133a23 _ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE + 159
9   node                                0x000000010014fdb9 _ZN2v88internalL21Builtin_HandleApiCallEiPPNS0_6ObjectEPNS0_7IsolateE + 538
10  ???                                 0x0000301a5d60740e 0x0 + 52889793885198
11  ???                                 0x0000301a5d6a074b 0x0 + 52889794512715
12  ???                                 0x0000301a5d607b75 0x0 + 52889793887093
lmorchard commented 9 years ago

By tracing calls and puking console.log all over the place, I tracked the segfault down to readMessage() in firefox-client/lib/client.js. But, from there, things get weird.

I "fixed" the segfault by adding a console.log to readMessage() like so:

  readMessage: function() {
    console.log('readMessage ' + this.incoming);
    var sep = this.incoming.toString().indexOf(':');

That is, everything works fine with that console.log in place. But, segfault returns when I comment it out. I suspect a bug in node / io.js, but not sure WTF is happening yet.

:confounded:

sole commented 9 years ago

This is the weirdest thing! and also you're amazingggg! I've no idea how to proceed further. Do you know if this happens in other systems? Just to discount if it's a Mac OS thing (?)

lmorchard commented 9 years ago

Haven't been able to confirm it happens on Windows or Linux. But, I can confirm it does not happen on node v0.10.38 on OS X, and it does happen on v0.11.4 & beyond. Might happen earlier, but I don't have a minimal test case yet and versions earlier than v0.11.4 don't seem compatible with all the node-firefox dependencies (which is weird, but whatever)

Asked for help in #node.js on freenode IRC, and people seemed stumped & asked me to file an issue against node. :laughing: :crying_cat_face:

lmorchard commented 9 years ago

Filed #25357 against node.js, based on a minimized test case.

So, I guess the best we can say at this point is don't use node-firefox with node>=0.11.0 on OS X

jeffgca commented 9 years ago

Isn't the right thing to do to look into a way around it until the upstream bug is resolved? Leaving the console.log in place feels dirty but there may be a less invasive way to get the same effect, eg calling process.nextTick or pumping the console's cursor forward and then back again.

lmorchard commented 9 years ago

Yeah, I'm actually looking into that... trying to come up with something that doesn't spew messages for every byte (or chunk) of network activity from the device.

FWIW, this also touches on #29, because the bug is triggered in firefox-client. Not the end of the world, because I can fork it and tweak all node-firefox modules to use the fork. But we may need to care for & feed that fork going forward. Also not a terrible thing.

lmorchard commented 9 years ago

Yeah, there might be a workaround. It's a magical accidental discovery and I have no idea why it works, but I can give it a shot in a fork of firefox-client

lmorchard commented 9 years ago

Crud. Workaround doesn't fix anything, just makes the problem more rare. So, it's exacerbated by more network activity because every chunk of data received has a chance of setting it off - i.e. I set up a small demo for myself with 2 devices and 2 simulators, fired off an install task against all of them, and the segfault returned.