Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

PhantomJS failed 2 times (timeout). Giving up. #84

Open
SET001 opened this issue Oct 26, 2015 · 40 comments
Open

PhantomJS failed 2 times (timeout). Giving up. #84

SET001 opened this issue Oct 26, 2015 · 40 comments

Comments

@SET001
Copy link

SET001 commented Oct 26, 2015

PhantomJS is not starting for some reason:

27 10 2015 00:00:39.452:INFO [karma]: Karma v0.13.14 server started at http://localhost:9876/
27 10 2015 00:00:39.459:INFO [launcher]: Starting browser PhantomJS
27 10 2015 00:01:39.475:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
27 10 2015 00:01:39.489:INFO [launcher]: Trying to start PhantomJS again (1/2).
27 10 2015 00:02:39.537:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
27 10 2015 00:02:39.544:INFO [launcher]: Trying to start PhantomJS again (2/2).
27 10 2015 00:03:39.562:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
27 10 2015 00:03:39.567:ERROR [launcher]: PhantomJS failed 2 times (timeout). Giving up.

nodejs: 0.12.0
phantomjs: 1.9.8

@marcofranssen
Copy link

Same issue here...

Node: 4.2.2
Karma 0.13.15
Karma-phantomjs-launcher 0.2.1
phantomjs 1.9.18

This is how we run it

karma start "web/js2/test/karma.conf.js" --no-colors --single-run --log-level info --reporters dots
19 11 2015 15:22:07.682:INFO [karma]: Karma v0.13.15 server started at http://localhost:9877/
19 11 2015 15:22:07.695:INFO [launcher]: Starting browser PhantomJS
19 11 2015 15:22:27.706:WARN [launcher]: PhantomJS have not captured in 20000 ms, killing.
19 11 2015 15:22:27.722:INFO [launcher]: Trying to start PhantomJS again (1/2).
19 11 2015 15:22:47.729:WARN [launcher]: PhantomJS have not captured in 20000 ms, killing.
19 11 2015 15:22:47.739:INFO [launcher]: Trying to start PhantomJS again (2/2).
19 11 2015 15:23:07.743:WARN [launcher]: PhantomJS have not captured in 20000 ms, killing.
19 11 2015 15:23:07.749:ERROR [launcher]: PhantomJS failed 2 times (timeout). Giving up.

Also tried with longer timeouts of 2 minutes, but it just doesn't work.

Running phantomjs manually like this seems to work since it just gives me the phantomjs REPL.

node_modules/phantomjs/bin/phantomjs
phantomjs> 

Also reported the issue over here karma-runner/karma#558 (comment)

@marcofranssen
Copy link

I figured out that we still had config in place which doesn't work in karma 0.13.

In karma 0.8 we have been using transports: ['flashsocket', 'xhr-polling', 'jsonp-polling']

I have changed that to transports: ['websocket', 'polling']

@mpiasta-ca
Copy link

I upgraded from 0.1.4 to 0.2.1, and PhantomJS is failing to launch. Reverting for now.

@kwhc
Copy link

kwhc commented Nov 29, 2015

Check to be sure something like xampp or another local web server isn't running on the same port.
My xampp and karma were set to run on 8080 so I just changed the karma port.

@zewish
Copy link

zewish commented Jan 3, 2016

Hello guys, I had the same problem today and I did some extensive debugging and testing of the karma and karma-phantomjs-launcher packages.

The issue here was actually in my /etc/hosts file which I edited earlier today. I seem to have removed the "localhost" entry, and Karma by default tries to listen on http://localhost:9876/ and waits for PhantomJS to open the page which seems to fail without a meaningful error if localhost could not be resolved.

If you have the same issue as mine you have two options:

  • add 127.0.0.1 localhost to the /etc/hosts file
  • run $ IP=127.0.0.1 karma start

Lots of pseudo-bugs could be escaped if karma had "127.0.0.1" as the default IP it's listening instead of "localhost" by the way :)

@tim-mc
Copy link

tim-mc commented Jan 4, 2016

@zewish this fixed the issue for me - I added 127.0.0.1 localhost to my hosts file (it had been removed when setting up my computer for my work dev environment) and the issue is no longer occurring.

ProductName:    Mac OS X
ProductVersion: 10.11.2
BuildVersion:   15C50

Node version: v4.2.2
NPM version: 2.14.7
Karma version: 0.13.9
karma-phantom-js-launcher version: 0.2.1
phantomjs version: 1.9.19

No errors were output that indicated that this was the issue.

@MartijnR
Copy link

MartijnR commented Jan 5, 2016

I had to change the port to resolve this issue. Odd because the browser runners were still working and were using the same port.

@mikelax
Copy link

mikelax commented Feb 1, 2016

I had the same issue
node: v4.2.4
phantomjs: 1.9.19
mac os: 10.10.5

For some reason my hosts file was deleted, after restoring a basic hosts file to /private/etc/hosts things started working again.

@Chuxel
Copy link

Chuxel commented Apr 27, 2016

I am seeing this same problem on Windows even when the HOSTS file contains localhost. We're trying to get things working in a CI environment - Specifically Visual Studio Team Services.

Environment details:

Node: 0.12.7 (64-bit)
npm: 2.11.3
Karma: 0.13.22
OS: Windows Server 2012 R2 [Version 6.3.9600]
PhantomJS: 2.1.7

Karma is starting on http://localhost:9876/ which appears to be free.

This repros with 1.0.0 and ^0.2 of karma-phantomjs-launcher but not ~0.1

Edit: ~0.1 works not ^0.1 obviously.

@missbruni
Copy link

Adding 127.0.0.1 localhost to my host file has also stopped the issue for me. Thanks!

@planavsky82
Copy link

@zewish thanks for that post. After hours of searching for info this fixed the issue for me as well.

@ghost
Copy link

ghost commented May 26, 2016

FYI, 127.0.0.1 localhost was in the hosts file, but the loopback interface had been deleted from the machine, which I confirmed by running ifconfig. Adding the loopback interface via ifconfig lo0 127.0.0.1 fixed the issue. I suggest some additional helper code, perhaps only executed when in debug mode. Since the launcher uses localhost to connect to karma's local server, it would be nice to have the launcher ping localhost and report if there is no response. Maybe also check if the specified port is accessible.

@jwang
Copy link

jwang commented Jun 23, 2016

I'm having the same problem as this, but none of the suggested items here of messing with/etc/host work.

node v6.2.2
npm 3.9.5
phantomjs 2.1.1
karma 1.0.0
karma-phantomjs-launcher 1.0.1


karma start --single-run
23 06 2016 13:46:45.511:INFO [karma]: Karma v1.0.0 server started at http://localhost:9876/
23 06 2016 13:46:45.514:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
23 06 2016 13:46:45.524:INFO [launcher]: Starting browser PhantomJS
23 06 2016 13:47:45.523:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
23 06 2016 13:47:47.525:WARN [launcher]: PhantomJS was not killed in 2000 ms, sending SIGKILL.
23 06 2016 13:47:49.526:WARN [launcher]: PhantomJS was not killed by SIGKILL in 2000 ms, continuing.

Edit: Forgot to mention this, but launchers like Chrome, Safari and such work fine. Additionally, PhantomJS actually works fine when used by other methods such as just running Mocha separately or through a different runner such as testem.

@kaicataldo
Copy link

Seeing the same thing as @jwang. Works fine in the latest versions of Node 4 and 5

@ralfius
Copy link

ralfius commented Jul 23, 2016

Had the same issue. Tried hostname: '127.0.0.1' with mapping 127.0.0.1 to localhost in hosts file. Ended up with changing the port: 9876 to port: 19876. After checking ports in use (with netstat -a under Windows) it was indeed already taken

@kolkov
Copy link

kolkov commented Aug 31, 2016

Had the same issue. When I stopped my Golang Web server, problem disappeared.

@gregorskii
Copy link

This is happening for me as well on Shippable Ci.

Any ideas?

@andrewphahn
Copy link

I was having the same issue after upgrading to macos sierra. Upgrading to the latest karma-phantomjs-launcher (and so phantomjs) fixed the issue.

Was using:
node v0.12.9
karma 0.12
karma-phantomjs-launcher 0.1.4
phantomjs (from karma-phantomjs-launcher) 1.9

Upgraded to:
node v0.12.9
karma 0.12
karma-phantomjs-launcher 1.0.2
phantomjs-prebuilt (from karma-phantomjs-launcher) 2.1.13

@gregorskii
Copy link

Will test updates on my end to confirm! Thanks!

@iplantemn
Copy link

I'm seeing the same problem. The configuration works fine on MacOS 10.11.6 (El Capitan), with Node v6.0.0 / npm 3.8.6, but on a TeamCity 9.1.6 agent running Windows with Node v4.2.2 / npm 2.14.7, it fails miserably with an error of PhantomJS have not captured in 60000 ms.

Here's an example stacktrace on TeamCity:

[08:58:40][exec] 02 11 2016 08:58:41.095:DEBUG [config]: autoWatch set to false, because of singleRun
[08:58:40][exec] 02 11 2016 08:58:41.102:DEBUG [plugin]: Loading plugin karma-jasmine.
[08:58:40][exec] 02 11 2016 08:58:41.107:DEBUG [plugin]: Loading plugin karma-chrome-launcher.
[08:58:40][exec] 02 11 2016 08:58:41.121:DEBUG [plugin]: Loading plugin karma-firefox-launcher.
[08:58:40][exec] 02 11 2016 08:58:41.128:DEBUG [plugin]: Loading plugin karma-phantomjs-launcher.
[08:58:40][exec] 02 11 2016 08:58:41.263:DEBUG [web-server]: Instantiating middleware
[08:58:41][exec] 02 11 2016 08:58:41.595:INFO [karma]: Karma v1.3.0 server started at http://localhost:9877/
[08:58:41][exec] 02 11 2016 08:58:41.596:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
[08:58:41][exec] 02 11 2016 08:58:41.616:INFO [launcher]: Starting browser PhantomJS
[08:58:41][exec] 02 11 2016 08:58:41.618:DEBUG [temp-dir]: Creating temp dir at E:\TCA\3\temp\buildTmp\karma-47802965
[08:58:41][exec] 02 11 2016 08:58:41.631:DEBUG [launcher]: E:\TCA\3\work\f900f2fe23d6c9b0\Preview\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs E:\TCA\3\temp\buildTmp\karma-47802965/capture.js
[08:59:41][exec] 02 11 2016 08:59:41.621:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
[08:59:43][exec] 02 11 2016 08:59:43.624:WARN [launcher]: PhantomJS was not killed in 2000 ms, sending SIGKILL.
[08:59:45][exec] 02 11 2016 08:59:45.627:WARN [launcher]: PhantomJS was not killed by SIGKILL in 2000 ms, continuing.
[08:59:45][exec] 02 11 2016 08:59:45.628:DEBUG [launcher]: Process PhantomJS exited with code -1
[08:59:45][exec] 02 11 2016 08:59:45.629:DEBUG [temp-dir]: Cleaning temp dir E:\TCA\3\temp\buildTmp\karma-47802965
[08:59:45][exec] 02 11 2016 08:59:45.637:DEBUG [launcher]: PhantomJS failed (timeout). Not restarting.
[08:59:45][exec] 02 11 2016 08:59:45.638:DEBUG [karma]: Run complete, exiting.
[08:59:45][exec] 02 11 2016 08:59:45.639:DEBUG [launcher]: Disconnecting all browsers
[08:59:45][exec] Warning: Task "karma:unit" failed.  Use --force to continue.
[08:59:45][exec] 
[08:59:45][exec] Aborted due to warnings.
[08:59:45][exec] npm ERR! Test failed.  See above for more details.

Here's a snippet of package.json:

"devDependencies": {
    "bower": "latest",
    "grunt": "^1.0.1",
    "grunt-cli": "^1.2.0",
    "grunt-contrib-jshint": "^1.0.0",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-istanbul-coverage": "^0.1.4",
    "grunt-karma": "^2.0.0",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-firefox-launcher": "^1.0.0",
    "karma-jasmine": "^1.0.2",
    "karma-phantomjs-launcher": "^1.0.2",
    "jasmine-core": "^2.5.2",
    "matchdep": "^1.0.1"
},
"scripts": {
    "postinstall": "node ./node_modules/bower/bin/bower install",
    "test": "node ./node_modules/.bin/grunt default"
}

And here's a snippet of karma.conf.js:

module.exports = function (config) {
'use strict';

config.set({
    frameworks: ['jasmine'],
    plugins: [
        'karma-jasmine',
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-phantomjs-launcher'
    ],
    files: [
        <...>
    ],
    exclude: [],
    preprocessors: {
    },
    reporters: ['progress']
    port: 9877,
    runnerPort: 9101,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['PhantomJS'],
    captureTimeout: 60000,
    singleRun: true
});

@vinicius33
Copy link

@andrewphahn thanks!

@iplantemn
Copy link

Issue solved! In our CI environment, we aren't getting the node modules by running npm install - we are zipping the node_modules directory locally and adding it to our source code.

Zipping it on a Mac and exploding it on Windows and attempting to use those modules, especially phantomjs-prebuilt, is the reason why it wasn't capturing.

I zipped it from Windows instead and it worked perfectly.

@LouisWayne
Copy link

@andrewphahn Yes, I updated karma-phantomjs-launcher (1.0.2), and it works fine now. Thanks!

@juan-m-medina
Copy link

I had this issue due to me having an instance of HttpDebugger open. Not a common issue, but adding here in case others with a similar setup experience the problem.

@phanikirancdonthi
Copy link

same issue with "karma-phantomjs-launcher": "1.0.2"

21 02 2017 14:54:51.066:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
21 02 2017 14:54:51.070:INFO [launcher]: Starting browser PhantomJS
21 02 2017 14:55:51.072:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
21 02 2017 14:55:51.088:INFO [launcher]: Trying to start PhantomJS again (1/2).
21 02 2017 14:56:51.090:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
21 02 2017 14:56:51.098:INFO [launcher]: Trying to start PhantomJS again (2/2).
21 02 2017 14:57:51.100:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
21 02 2017 14:57:51.108:ERROR [launcher]: PhantomJS failed 2 times (timeout). Giving up.

@danroberts
Copy link

Is there any way to set it up so that karma checks if something is running on the specified port before launching and then tries to find another open port?

@silverbucket
Copy link

Same problems here:

node: 7.7.2
npm: 4.1.2
mocha: 3.2.0
karma: 1.5.0
macOS: 10.12.3

Chrome runs fine, but Firefox and Safari both get timeout messages until the tests abort:

13 03 2017 23:26:09.954:INFO [framework.detect-browsers]: The following browsers were detected on your system: [ 'Chrome', 'Firefox', 'Safari' ]
13 03 2017 23:26:11.061:INFO [karma]: Writing browser console to file: test-results/karma.log
13 03 2017 23:26:13.638:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/
13 03 2017 23:26:13.638:INFO [launcher]: Launching browsers Chrome, Firefox, Safari with unlimited concurrency
13 03 2017 23:26:13.664:INFO [launcher]: Starting browser Chrome
13 03 2017 23:26:13.675:INFO [launcher]: Starting browser Firefox
13 03 2017 23:26:13.681:INFO [launcher]: Starting browser Safari
13 03 2017 23:26:15.040:INFO [Chrome 56.0.2924 (Mac OS X 10.12.3)]: Connected on socket rFW_kSHrBqLu3I2hAAAA with id 54548385
13 03 2017 23:27:13.674:WARN [launcher]: Firefox have not captured in 60000 ms, killing.
13 03 2017 23:27:13.682:WARN [launcher]: Safari have not captured in 60000 ms, killing.
13 03 2017 23:27:13.704:INFO [launcher]: Trying to start Safari again (1/2).
13 03 2017 23:27:13.732:INFO [launcher]: Trying to start Firefox again (1/2).
13 03 2017 23:28:13.703:WARN [launcher]: Safari have not captured in 60000 ms, killing.
13 03 2017 23:28:13.721:INFO [launcher]: Trying to start Safari again (2/2).
13 03 2017 23:28:13.734:WARN [launcher]: Firefox have not captured in 60000 ms, killing.
13 03 2017 23:28:13.793:INFO [launcher]: Trying to start Firefox again (2/2).
13 03 2017 23:29:13.729:WARN [launcher]: Safari have not captured in 60000 ms, killing.
13 03 2017 23:29:13.747:ERROR [launcher]: Safari failed 2 times (timeout). Giving up.
13 03 2017 23:29:13.792:WARN [launcher]: Firefox have not captured in 60000 ms, killing.
13 03 2017 23:29:13.849:ERROR [launcher]: Firefox failed 2 times (timeout). Giving up.

@SRferrero
Copy link

SRferrero commented Mar 15, 2017

[ @silverbucket ] I have almost same versions as you have:

node: 7.7.1
npm: 4.1.2
karma: 1.5.0
macOS: 10.12.3
karma-phantomjs-launcher 1.0.2
but I updated to karma 1.5.0 and when running tests I get

15 03 2017 13:29:14.157:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing. 15 03 2017 13:30:14.178:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing. 15 03 2017 13:31:14.195:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing. 15 03 2017 13:31:14.208:ERROR [launcher]: PhantomJS failed 2 times (timeout). Giving up. npm ERR! Test failed. See above for more details.

If I downgrade to karma 1.3.0 (after that version it wont work) everything seems to be a great success

@rdadalski
Copy link

rdadalski commented Mar 18, 2017

I've just updated karma-phantomjs-launcher in my devDependencies and it worked...

"devDependencies": {
"angular-mocks": "^1.4.1",
"isparta-instrumenter-loader": "^0.2.1",
"jasmine-core": "^2.3.4",
"karma": "^0.13.9",
"karma-coverage": "^0.4.2",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.5",
"karma-spec-reporter": "0.0.19",
"karma-webpack": "^1.5.1",
"null-loader": "^0.1.1",
"phantomjs": "^1.9.17"
}

@CFenner
Copy link

CFenner commented Mar 29, 2017

For me this is working or running npm test with sudo:

    "karma": "1.3.0",
    "karma-phantomjs-launcher": "^1.0.4",

@tiefling
Copy link

tiefling commented Apr 6, 2017

I fixed this by fixing karma version at 1.3.0

There must be a bug in 1.5.0, which it was using before.

@SRferrero I've added the issue at karma-runner/karma#2647 - feel free to add more info.

@davedx
Copy link

davedx commented Apr 6, 2017

For me it was an older version of karma while running a newer version of nodejs -- socket.io was using a deprecated way to get EventEmitter, and instead of crashing it was just hanging trying to establish the connection to phantomjs I guess.

Solution was to downgrade node to <v6 (easier than upgrading all our packages in our relatively maintenance mode project)

@pierrettemugisha
Copy link

pierrettemugisha commented Apr 19, 2017

Have the same issue. I don't know what went wrong, as of yesterday it was working fine. But this morning when I opened my laptop to continue writing tests, the browser was not starting. I didn't think of it much, but added Chrome to use that instead for also easy debug purpose. It is when I tried to build my maven project that I come to realize that it was a big issue, as it was failing my build.
Adding my localhost in the hosts file didn't change anything for me. Not even downgrading my karma version from 1.5.0 to 1.3.0. I can't downgrade the node version too, as it may work, but the project is being deployed to a remote server where the new node is of version 7.7.3. So the change I would make may not work there.

@ghost
Copy link

ghost commented May 4, 2017

PhantomJS does this for me.

Removing all 'use strict'; fixed it, but what a pain.

@bkotrys
Copy link

bkotrys commented May 12, 2017

I solved this problem. Link: #126

@mbjelac
Copy link

mbjelac commented May 26, 2017

@bkotrys - issue #126 has 10^32934 variations and solution attempts ... you could be more specific. but thanks anyway, I stumbled upon a solution in a comment on that issue:

folks, if you're running this in a docker container, don't use an Alpine image.

for details, see issue comments:
#126 (comment)
#126 (comment)

@abhipanda
Copy link

It works by deleting the node_modules and installed it again 👍

billgsm added a commit to billgsm/webpack that referenced this issue Jul 18, 2017
karma-runner/karma-phantomjs-launcher#84 (comment)
If localhost is removed from /etc/hosts phantomjs won't start
@jrdncchr
Copy link

@davidlbyrne
Copy link

Easy solve. I had a service that was already bound to the port. So I modified the port in my karma.conf.js and it worked.

@danbrianwhite
Copy link

To help others who want to add the IP to source control without an extra package for .env, add
process.env.IP = '127.0.0.1';
to your code's test path or gulpfile.js

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests