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

When using polling a failed request returns with a CORS error. #211

Closed
nherment opened this issue Jan 9, 2014 · 11 comments
Closed

When using polling a failed request returns with a CORS error. #211

nherment opened this issue Jan 9, 2014 · 11 comments

Comments

@nherment
Copy link

nherment commented Jan 9, 2014

Hi,

When doing a CORS polling request, if the request fails the verification (here), the browser does not show the error returned by engine.io but show a CORS error instead.

This makes troubleshooting very difficult.

I believe that this is happening because the CORS headers are added only when the request is recognized as xhr-polling.

The CORS headers are supposedly added during the handshake.

Steps to reproduce

2 domains: subA.domain.com subB.domain.com

// this request emerged from a webpage on subA.domain.com
$.get(
    'https://subB.domain.com/engine.io/?EIO=2&transport=polling&sid=thisSidIsNotValid'
  );
XMLHttpRequest cannot load https://subB.domain.com/engine.io/?EIO=2&transport=polling&sid=thisSidIsNotValid. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://subA.domain.com' is therefore not allowed access.

Not sure how easy it would be to fix this.

It's happening with engine.io 0.7.9 but after looking at the code I believe it should be reproducible on the current master branch.

@kapouer
Copy link
Contributor

kapouer commented Jan 9, 2014

Isn't this related to #177 ?

@mokesmokes
Copy link
Contributor

What happens if you timestamp the request to bust caching? Cached responses/headers will often screw up cross origin requests. If for some reason your browser cached a same-origin request to the same resource - this is the error you will see when you try to get the resource cross origin.

@nherment
Copy link
Author

nherment commented Jan 9, 2014

@kapouer I don't think it is related unless I miss something.

@mokesmokes I tried and it does not help

@mokesmokes
Copy link
Contributor

What does the Chrome network panel show you? Is the request actually going out to the server? Look at the request and response headers, etc.

@nherment
Copy link
Author

nherment commented Jan 9, 2014

It is a typical CORS error. I can see the request headers not the response. The server is answering the request with a HTTP 400 code but the browser is blocking the response. I assume it is because the response headers are missing the CORS headers.

I think I understand the problem pretty well. I'd be happy to chat about it over skype or hangout.

@mokesmokes
Copy link
Contributor

Yup, I see it. sendErrorMessage() should be setting CORS headers if required. It's a bug.

@trabus
Copy link

trabus commented May 3, 2014

I have been experiencing this as well, but have been able to isolate the cause for our situation, and it is scale related.

We are using a hardware load balancer in front of several servers, which was using cookies for stickiness. However, OPTIONS preflights don't usually contain cookies, and so they were getting routed to the wrong server frequently. Because the request was sent to the wrong server, it sees the request coming to a non-existent socket and responds with a 400/Bad request. The response code is contained in the transport, so any misdirected requests will see these errors.

To temporarily fix this, we are intercepting all OPTIONS requests and responding from the load balancer. I would like to propose the idea of responding to all preflight requests from the server level, to mitigate this issue.

I have successfully done this locally already by moving the OPTIONS response code to server.js, but wanted to get thoughts before submitting a pull request.

@mokesmokes
Copy link
Contributor

But the bug occurs even without preflighted requests. I think the fix should be as I wrote in the my previous comment.

@defunctzombie
Copy link
Contributor

@mokesmokes can you provide a patch?

@mokesmokes
Copy link
Contributor

Yup, will do.

@rauchg rauchg closed this as completed in b98406a Jun 4, 2014
rauchg added a commit that referenced this issue Jun 4, 2014
fix GH-211, set CORS headers when sending error message
@nherment
Copy link
Author

nherment commented Jun 4, 2014

Thanks !
Cc @vanchi-zendesk @samshull

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

No branches or pull requests

5 participants