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

Client closed connection before receiving entire response #820

Closed
soundstep opened this issue Nov 12, 2013 · 8 comments
Closed

Client closed connection before receiving entire response #820

soundstep opened this issue Nov 12, 2013 · 8 comments

Comments

@soundstep
Copy link

Testing a service that does a jsonp request (using reqwest).

I've got the same mocha + chai tests running well in the browser but I got an error in Karma + PhantomJS: a timeout on the request.

Charles is telling me that the request was closed:
"Client closed connection before receiving entire response"

And indeed the json is cut in the middle.

Not that the url of the request is coming from an external API.

I'll post a repo later today so you can fork and run the tests.

Cheers.

@soundstep
Copy link
Author

if you forked that repo:
https://github.com/soundstep/itv-test

$ npm install
$ grunt install grunt-cli -g
$ npm instal karma -g
$ npm instal mocha -g

Then start the tests:

$ grunt karma

You should get:

INFO [karma]: Karma v0.10.4 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.2 (Mac OS X)]: Connected on socket ZC9I7XbqLAa6aEioNImj
.....
PhantomJS 1.9.2 (Mac OS X) search service perform a search FAILED
    timeout of 5000ms exceeded
..
PhantomJS 1.9.2 (Mac OS X): Executed 8 of 8 (1 FAILED) (6.615 secs / 6.504 secs)

Charles is telling:

URL: http://mercury.itv.com/api/json/dotcom/programme/searchatoz/a
Status: Complete
Failure: Client closed connection before receiving entire response
Response Code: 200 OK

The response is kind of stopped in the middle (see the failure message) so I thought about PhantomJS.

I also noticed that I can't reach this API from something else than localhost but I haven't been able to run Karma on the port 80.

This might not be an issue but rather a strange behavior of the API that shows part of the request while it shouldn't if there was CORS issue.

Is there anything specific to do to reach external API with Karma usually?

Romu

@vojtajina
Copy link
Contributor

How big is the JSON file? It might be related to the gzip problem, can you try hack your Karma:
node_modules/karma/lib/web-server.js, remove line 55
https://github.com/karma-runner/karma/blob/master/lib/web-server.js#L55

Put there some console.log just to make sure that you editted the right file.

Karma listens on configured port (9876 by default) on all interfaces, so you should be able to access Karma from everywhere where you can access the machine where Karma is running. You can totally run Karma on port 80, but you will probably have to start it with sudo, as 80 port is reserved.

Try to fetch the file through http://localhost:9876/base/xxx.json - note that Karma serves your files under /base.

@vojtajina
Copy link
Contributor

@soundstep did you try it?

@soundstep
Copy link
Author

I can't really remove this line, it is creating some errors I think.

The JSON is really a file but coming from API external which only allow the domain "localhost". I think that is the problem. It is just weird that I receive part of the file instead of getting a 401 or something.

The error removing the line 55 was:

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.4 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.2 (Mac OS X)]: Connected on socket CF0t_NWzQzTzQkNX7ffK
WARN [web-server]: 404: /base/node_modules/chai/chai.js?1381402002000
WARN [web-server]: 404: /base/node_modules/karma-chai/adapter.js?1376684533000
WARN [web-server]: 404: /base/node_modules/mocha/mocha.js?1383446689000
WARN [web-server]: 404: /base/node_modules/karma-requirejs/lib/require.js?1375082464000
WARN [web-server]: 404: /base/node_modules/karma-requirejs/lib/adapter.js?1375781077000
WARN [web-server]: 404: /base/tests/assets/karma-runner.js?1384254592000
WARN [web-server]: 404: /base/node_modules/karma-mocha/lib/adapter.js?1375780960000
PhantomJS 1.9.2 (Mac OS X): Executed 0 of 0 ERROR (0.012 secs / 0 secs)
Warning: Task "karma:unit" failed. Use --force to continue.

@vojtajina
Copy link
Contributor

Sorry I think the line number might have gotten confused, here's a link to specific tag:
https://github.com/karma-runner/karma/blob/v0.10.6/lib/web-server.js#L52

Do exactly this 5ee886b

@soundstep
Copy link
Author

I see. It doesn't solve the problem but it is not directly related to karma.
I would need karma to run the test from a localhost:80 server, I'll check if that's configurable.
The json wouldn't be able accessible from another port (CORD issues).

It is good to know though, thanks for that

@vojtajina
Copy link
Contributor

@soundstep I'm confused what are you talking about? Is this JSON file served by Karma ?

Did you try disabling the gzip?

@soundstep
Copy link
Author

No the file is not served by Karma, I gave the URL above. I found that localhost:80 only is allowed, hence the error. And I've been mislead as even though unauthorized, I get part of the response (json).

So the issue is probably not in Karma as I suppose it is serving a specific port (not allowed by the remote server): localhost:KARMA_PORT

Sorry about the confusion, the ticket can probably be closed.

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

No branches or pull requests

2 participants