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

Unexpected response code 200 only on emulator #92

Closed
alxArad opened this issue Sep 18, 2017 · 6 comments
Closed

Unexpected response code 200 only on emulator #92

alxArad opened this issue Sep 18, 2017 · 6 comments

Comments

@alxArad
Copy link

alxArad commented Sep 18, 2017

Hi,

I get the following error from time to time (only on emulator):

BasicNetwork.performRequest: Unexpected response code 200.

The error is thrown from the BasicNetwork class line 238 (when trying to read from the HttpEntity.getContent input stream - method entityToBytes(HttpEntity)).

I must mention I do not use any proxy when communicating with the backend; the backend is accessed via wireless router - my PC and the backend are in the same network.
Also, I checked the backend logs and the response was properly sent, so no idea why this error happens.

I use Volley 1.0 (compile 'com.android.volley:volley:1.0.0')

Thanks,
Alex.

@jpd236
Copy link
Collaborator

jpd236 commented Sep 18, 2017

Would you be able to provide the full stack trace / exception beyond just entityToBytes? (i.e. by modifying the line of code that logs "Unexpected response code" to include the IOException as well). It sounds like the HTTP stack you are using is what's failing. Which one is it - have you tried using a different one?

Would also be good to know the emulator version you are using, and ideally, some sample code that reproduces the issue that we could run to investigate further, if possible.

@alxArad
Copy link
Author

alxArad commented Sep 19, 2017

Thank you for the quick response!

The caller of the entityToBytes is performRequest from the same class, BasicNetwork. I've attached 2 screenshots, one of them is the stack trace.
In the other screenshot you can see the Http stack used is HurlStack. Also, the error is indeed an IO error, more precisely an EOF exeception with message: "Not found:size=1 content=0"

The simulator I use is:
Nexus 6P API 23 (Android 6.0 Google APIs x86)

Sample code:

private RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {

            HttpStack stack = new HurlStack();
            Network network = new BasicNetwork(stack);

            RequestQueue queue = new RequestQueue(new NoCache(), network, Constants.DEFAULT_NETWORK_THREAD_POOL_SIZE);
            queue.start();

            mRequestQueue = queue;

        }
        return mRequestQueue;
    }
<T> void addToRequestQueue(Request<T> req) {
        req.setShouldCache(false);
        mRequestQueue.add(req);
    }

Thanks!

stack1
stack2

@jpd236
Copy link
Collaborator

jpd236 commented Sep 19, 2017

So HurlStack is more or less just a thin wrapper around HttpUrlConnection. The EOFException is presumably coming from there when trying to make the connection. I don't think there is much that Volley can do about this, short of applying a safe workaround if there's a known platform bug.

The stack traces of the cause chain would be good to look at, since the exception is being thrown by some platform class under the covers. Otherwise, I suspect you would reproduce the same issue if you just used HttpUrlConnection directly, which means there's unfortunately not much Volley can do.

Searching for the exception indicates a number of potential issues such as https://stackoverflow.com/questions/35990044/android-httpurlconnection-url-doesnt-work-on-emulator indicating networking issues on the machine in question which explained why it was emulator only.

@alxArad
Copy link
Author

alxArad commented Sep 20, 2017

My thoughts were the same...most probably the issue is related to the PC's network. I will also try to reproduce it on my MAC (and I think it will not reproduce, just as on a real phone).

From my point of view the issue can be closed now.
Thanks!

@felangga
Copy link

felangga commented Dec 2, 2019

Hey I got this error, but not in emulator, I'm running on real device

@tarukhan19
Copy link

Hey I got this error, but not in emulator, I'm running on real device

Hey. did u find the solution for that

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

4 participants