WSL: PhantomJS immediately crashing after launch through Karma
Please use the following bug reporting template to help produce actionable and reproducible issues:
- A brief description
PhantomJS seems to be able to be launched standalone, but cannot be used with Karma. This issue has also been posted to the karma-phantomjs-launcher issues page with no workaround found. karma-runner/karma-phantomjs-launcher#124
I’m using a workaround to get past #468 since Webpack requires os.interfaces. Part of me wonders if this could be the cause.
- Expected results
Headless execution of tests with PhantomJS
- Actual results (with terminal output if applicable) `> NODE_ENV=test ./node_modules/karma/bin/karma start karma.conf.js
Info: No mac address - uniqid() falls back to uniqid.process(). no interfaces found 15 08 2016 17:30:27.960:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/ 15 08 2016 17:30:27.963:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency 15 08 2016 17:30:27.977:INFO [launcher]: Starting browser PhantomJS 15 08 2016 17:30:29.554:ERROR [phantomjs.launcher]: PhantomJS has crashed. Please read the bug reporting guide at http://phantomjs.org/bug-reporting.html and file a bug report.
15 08 2016 17:30:29.556:ERROR [launcher]: Cannot start PhantomJS
15 08 2016 17:30:29.563:INFO [launcher]: Trying to start PhantomJS again (1/2). 15 08 2016 17:30:30.035:ERROR [phantomjs.launcher]: PhantomJS has crashed. Please read the bug reporting guide at http://phantomjs.org/bug-reporting.html and file a bug report.
15 08 2016 17:30:30.036:ERROR [launcher]: Cannot start PhantomJS
15 08 2016 17:30:30.039:INFO [launcher]: Trying to start PhantomJS again (2/2). 15 08 2016 17:30:30.507:ERROR [phantomjs.launcher]: PhantomJS has crashed. Please read the bug reporting guide at http://phantomjs.org/bug-reporting.html and file a bug report.
15 08 2016 17:30:30.508:ERROR [launcher]: Cannot start PhantomJS
15 08 2016 17:30:30.511:ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.`
- Your Windows build number
Anniversary Update
- Steps / commands required to reproduce the error
Run Karma with PhantomJS
- Strace of the failing command
I can’t figure out how to get a strace on this, but if someone knows how to I’ll get it up.
- Required packages and commands to install
Webpack, Karma, PhantomJS-prebuilt through npm, karma-webpack, karma-phantomjs-launcher is I think all needed to reproduce. The use case for this project is using Chai and Mocha.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 19
- Comments: 54 (16 by maintainers)
@mbland (and @therealkenc) great debugging and details. Thanks for digging to the bottom of this. Yes,
non-blocking connectis definitely in our backlog. So, far, it (the lack of non-blocking connect) was only causing marginal problems (such as warnings) etc. But, with this it seems like we are getting into functional issues without proper support fornon-blocking connect. We will try to prioritize this. Marking this as dupe of #1584. Thanks again for the great investigation!Just an update that
non-blocking connectis on it’s way and will also be available on Fall Creators Update.OK, pretty sure I nailed it: it is the lack of nonblocking
connect()that’s causing the crash. What follows is my analysis from the “Culprit” section of my demo repo.cc: @sunilmut @therealkenc
At this point I’m reasonably certain that the failure is due to the present lack of support for nonblocking
connect()calls on WSL (Microsoft/BashOnWindows#1584) throwing off the low-level QT socket libraries. The presence ofpselect()calls in the successful, native Ubuntu strace logs was a hint: nonblockingconnect()calls typically returnEINPROGRESS, after which clients should useselect()(orpselect()) to wait for the socket to be writable.Compare the system calls from
logs/Ubuntu-17.04-debug/strace.log:to those from
logs/wsl-debug/strace.log:We’ll piece together three related stack traces from
gdb/socket.txt,gdb/connect.txt, andgdb/stack-trace.txtto demonstrate how this series of system calls were generated and led to the crash. All of them come from a call toWebCore::WebSocket::create, which results in a call toQAbstractSocket::connectToHost:The paths to QT source files that follow are relative to the root of the PhantomJS repo at tag
2.1.1after runningpython ./build.py -d. The common starting point for each stack trace is this line fromQAbstractSocket::connectToHostatsrc/qt/qtbase/src/network/socket/qabstractsocket.cpp:1652:The stack trace for the WSL
socket()call (gdb/socket.txt) file shows that at this point, the the underlying socket is created by a call toQNativeSocketEnginePrivate::createNewSocketatsrc/qt/qtbase/src/network/socket/qnativesocketengine_unix.cpp:219. This line creates a socket with the nonblocking option hardcoded:The stack trace for the WSL
connect()call (gdb/connect.txt) shows a call toQAbstractSocketPrivate::_q_connectToNextAddressatsrc/qt/qtbase/src/network/socket/qabstractsocket.cpp:1130, which is the beginnning of this block:This
QNativeSocketEngine::connectToHostcall (note: different from theQAbstractSocket::connectToHostcall higher in the stack) in turn callsQNativeSocketEnginePrivate::nativeConnectatsrc/qt/qtbase/src/network/socket/qnativesocketengine_unix.cpp:389, which points to a call toqt_safe_connect:If the underlying
connect()andqt_safe_connecthad returnedEINPROGRESS, the correctsocketStatewould’ve been set,NativeSocketEnginePrivate::nativeConnectwould’ve returnedfalse, andQAbstractSocketPrivate::_q_connectToNextAddresswould’ve set up thepselect()notification. Instead,connect()returns zero and the function returnstrue, leading to theQAbstractSocketPrivate::fetchConnectionParameterscall atsrc/qt/qtbase/src/network/socket/qabstractsocket.cpp:1132:This in turn produces our final stack trace:
The assertion in
WebCore::WebSocketChannel::didOpenSocketStreamatsrc/qt/qtwebkit/Source/WebCore/Modules/websockets/WebSocketChannel.cpp:257is:which under further inspection in GDB reveals:
To save folks a click-through: The underlying issue is WSL’s lack of support for
TCP_KEEPCNTas a socket flag.@Bradleycorn Are you sure you’ve still got the issue, or that you’ve actually got the FCU installed? Here’s what I see in my WSL environment after installing the FCU (not sure what it was before):
The reason I ask is becuase I’m happy to report that this is what I see running in my mbland/custom-links project at commit 2fa5a50 (after having to do an explicit
npm install phantomjs-prebuilt):Perhaps @sunilmut and @benhillis may want others to confirm as well, but from my perspective, this and #1584 can be closed. 😃
Good to find this. It’s the first blocker I’ve run into in about 2 months since switching to using WSL for dev full time.
I mean, aside from vi being broken
Sorry for the thread spam (I spent so long editing that first reply!), but here’s proof of my
gdbrun, FWIW:In one tmux pane:
In another tmux pane:
Hi all, just wanted to ping on this thread as well. The latests Windows 10 builds seem to have fixed a good number of issues in socket-related system calls, which have let me run most of my NodeJS web app on Windows bash. Except for my client-side unit tests based on PhantomJS, which seem to depend on this issue. Since I don’t see much activity on here, I was wondering what the state is. Thanks all!
@bmayen test it