0.9.8.5674 fetch() error on Android

Hi! A possible bug found in 0.9.8.5674: fetch() returns partial data on Android (err=“Unexpected end of input” during JSON parse). Seems to me a bug in buffer concatenation. (Only affects the Android implementation.)

Do you have a testcase? It works here.

fetch("https://api.500px.com/v1/photos?feature=popular&image_size=30,1080&rpp=40&consumer_key=G7ZWcGQU5W395mCb0xx3dccp6x0fvQB8G8JCSaDg")
.then(function(response) {
    debug_log(JSON.stringify(response));
});

response here gets filled with the first data chunk on Android.

In the simulator and on iOS the same code works fine.

Hi, we’ve managed to reproduce the issue now, and are looking into fixing it.

jveres, you’ll love this one :stuck_out_tongue:

I’ve been digging through piles of info on chunked http streams, text encodings and androids HttpUrlConnection…but turns out it’s none of that:

android’s logcat has a line limit of 4096 characters

Madness, so when I debug_log the length of the string I get 227404.

I did see that the string recieveing code I had written was very inefficient so that will be fixed in the next release thanks to your question.

Hope this helps, I’m going back to reading android code and sighing

Kill two birds with one stone hehe I love this one indeed:) Thanks Chris!

Seems not yet fixed in the latest release.

Just want to clarify, did you try debug_log(JSON.stringify(response.length)); and did you get a number higher than 4096?

We will change debug_log so that on android it’ll split the output into 4096 long chunks, but that’ll be in a release a week or 2 from now.

The testcase revealed the logcat thing which I probably wouldn’t either call a bug:) but at least good to know. That’s bird no.1, but my real problem (bird no.2) is that response.json() gives exception: Unexpected end of input.

Sorry for the misleading testcase Chris, since I was not aware of that logcat length limit.

So my better sample is:

fetch("https://api.500px.com/v1/photos?feature=popular&image_size=30,1080&rpp=40&consumer_key=G7ZWcGQU5W395mCb0xx3dccp6x0fvQB8G8JCSaDg")
.then(function(response) {
  debug_log(JSON.stringify(response.json()));
});

See related https://www.fusetools.com/community/forums/howto_discussions/non-ascii_characters_breaking_fetch_request_on_and