-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
1.4.0 New line in String causes retrofit.RetrofitError: java.io.EOFException #397
Comments
I have found out what causes the problem, this is ANDROID AOSP bug. More here: http://stackoverflow.com/questions/19258518/android-httpurlconnection-eofexception I am not really sure how it should be "fixed" in RetroFit. It was already fixed in AOSP but the bug is still there in older versions. |
Are you saying that one of the fields in the |
Hi Jake, Yes indeed, one of the fields in the Announcement or basically any String causes that. I tried both 4.1 and 4.4.2 KitKat. I am using default serialization. I am not so sure if I am using any OkHttp. Also: it's random, sometimes it works, sometimes it doesn't even with the same data. |
Thanks I'll try to repro soon. If you are able to turn on logging ( |
I tested this out in my app. API 18, Retrofit 1.4.1, OkHttp 1.3.0 - and everything seems to be okay when POSTing fields with multiple new lines, though, as you mention, it is intermittent so it's possible I just haven't hit it. The request body looked something like this (some data redacted, sorry):
|
retrofit 1.4.1, I noticed the same exception. I tested on nexus 4 with android 4.4.2, no issues. Then I tested on samsung galaxy s3 mini with android 4.1.9 and got the eof exception (only for post requests). This happens randomly, but must of the time. Further I noticed, that I have to retry the async call when getting this exception. On second try it will do the rest call.
👍 for a fix @JakeWharton My dirty fix:
|
I'm also seeing this same issue randomly (on POST requests). I never see this on a device running Android 4.4.2 (including Nexus and Galaxy S4), but I'm seeing this on several devices running Android 4.3 or less (including the Android 4.3 Emulator). It seems that if I do back-to-back calls (using the very same call), that we see this issue happen. It actually appears that it happens on every-other call (the first call succeeds, the next call throws an EOFException, then the next call succeeds, repeat). I'm assuming that something is getting reset after the Exception. Update: I'm seeing this with only POST and PUT back-to-back calls that contain @Body. Should I be resetting something with retrofit between calls? FYI... The only work around is to watch for the "EOFException" and the retry (EOFException happens on every other call) |
@jeffdcamp @artworkad do you have update for this? Having same problem, it happens often but randomly. |
@gwvatieri check for exception and retry, this is the only fix at the moment
|
Or include and use OkHttp. That worked for me if I remember correctly. |
I have seen that @artworkad, I'll give it a try, thanks. @ansgarm was OkHttp used by default when present? |
Yes, it is. Simply adding it to my gradle build files solved the problem |
@ansgarm I'll include it and try. Can't reproduce it systematically so not sure how to test it. |
My only work-around is to retry (just like what @artworkad mentioned) (kinda painful to put that everywhere) |
Hey @jeffdcamp have you tried to include OKHttp? @ansgarm problem with cache after using it? |
I experienced this issue on a Nexus 5 running 4.3. It would seem to occur after some time had passed since the last request. It would always work the second time and it only seemed to occur with POST requests. @gwvatieri I switched over to OKHttp and wow, my requests were about fifty percent faster. I didn't see this issue anymore after switching. I just .setClient(new OKClient()) when building the RestAdapter. |
Hey @mattblang you don't need to set it manually, it's done automatically, you just need to include the library in your classpath. I did it and it looks like the issue is no longer happening, I'll confirm it later.
|
For me, it's still happening with the okhttp library included in the dependencies. (Nexus 4, Android 4.4) |
I finally got around to a situation that I was reproducing this error on every-other-call and I finally added the following to my project: compile 'com.squareup.okhttp:okhttp:1.5.4' By doing so, it seems to help quite a bit with this issue (I don't hardly ever see the same error when doing a POST now). |
I also am getting this error when issuing a POST request with String data from a multitext EditText in Android. it occurs every time for me, not every other time. |
Still can't repro. Seeing an actual request body that causes this would help greatly. |
For us.... this only happens with the following:
as stated before.... our work-around to this issue is to simply depend on okhttp:1.5.4. |
It appears that this problem has disappeared with Retrofit 1.6.x. Is anybody still experiencing this? |
I just get it with 1.6.1 Caused by: java.io.EOFException |
Currently using Retrofit 1.6.0 and getting a EOFException intermittently while doing POST. Not using OKHttp, running on Android 4.2.2 when it happens. |
This is very bad performance for the server side, can you imagine one person make 2-3 request to succeed, and you multiply that by the number of users and their actions. |
Issue not fixed. I'm using the latest Retrofit, and occasionally get exceptions mentioned before. |
Are you using okhttp 2.0? I used to have this error and after adding it, it never happened again. Marcel Pintó
|
As I said, I tried to use it, but error still happens. |
I have the same bug and using okhttp doesn't solve my problem. 08-13 10:09:29.121: D/Retrofit(19633): java.io.EOFException |
I'm running into the same issue. It's happening whether or not I use okhttp 2.0 or normal httpurlconnection. Only seems to occur on POST and only when I have an empty post body. |
@JakeWharton Hi Jake, are u able to reopen and look into this issue since it seems like it is not resolved simply by using OKHttp2.0. |
I was having the same problem while doing a GET. In my case, what was triggering this error was the fact that this was an authenticated GET and I was encoding my key/secret using Base64.encodeToString() to generate the corresponding header. The problem was that the generated string contained a new line (\n) inside of it, causing the server to misbehave and return a null response. This null response was responsible for this EOFException. The solution was to simple remove the \n from the encoded string. I know this is a specific problem to my app, but since there doesn't seem to be a consensus on how to reproduce this, I guess any sort of feedback helps. |
+1 |
It looks that the more robust option is to retry the request. |
Working well now after using okhttp |
Just run into this error on different 4.4.x Devices.
A request made with a rest client yields following headers.
Tried with |
Hi, same problem here, with 1.7.1, and Samsung Galaxy Tab GT-P5110. Here is the log : |
Troubled by the death of me, how to solve? |
I solved it by switching to OkHttp. |
I just used okhttp 2.1.0 version, there are still problems, help look?
|
I got this error and switch to okhttp did not help.
versions:
@GaryHost What is your version of okhttp? |
@grub-
|
I can reproduce the error for every POST request I send. Here is my project setup. Please let me know if I can add any further information. app/build.gradle: compile 'com.squareup.dagger:dagger:1.2.2'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.retrofit:retrofit:1.8.0'
compile 'com.squareup.retrofit:converter-jackson:1.8.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.0'
compile 'io.reactivex:rxandroid:0.23.0' ReportsService.java: public interface ReportsService {
@POST("/")
public Observable<CreateReportResponse> createReport(
@Body Report report
);
} ApiModule.java: public final class ApiModule {
public static final String API_URL = "http://100.200.100.200:8000";
public static final String REPORTS = "REPORTS";
@Provides
@Singleton
@Named(REPORTS)
Endpoint provideReportsEndpoint() {
return Endpoints.newFixedEndpoint(API_URL);
}
@Provides
@Singleton
ObjectMapper provideObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
return objectMapper;
}
@Provides
@Singleton
@Named(REPORTS)
ReportsService provideReportsService(
@Named(REPORTS) Endpoint endpoint,
ObjectMapper objectMapper) {
return createRestAdapterBuilder(objectMapper)
.setEndpoint(endpoint)
.build()
.create(ReportsService.class);
}
private RestAdapter.Builder createRestAdapterBuilder(ObjectMapper objectMapper) {
return new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setConverter(new JacksonConverter(objectMapper))
.setRequestInterceptor(request -> {
request.addHeader("Accept", "application/json");
});
}
} Report.java: public class Report {
public String userName;
public String emailAddress;
public Report(String userName, String emailAddress) {
this.userName = userName;
this.emailAddress = emailAddress;
}
} fragment_new_report.xml: <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/new_report_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_user_name"
android:layout_gravity="center_horizontal" />
<EditText
android:id="@+id/new_report_email_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_email_address"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</ScrollView> NewReportFragment: protected void onSubmitReport() {
Editable userName = userNameEditText.getText();
Editable emailAddress = emailAddressEditText.getText();
Report report = new Report(
userName.toString(),
emailAddress.toString());
createReport(report);
}
protected void createReport(final Report Report) {
Observable<CreateReportResponse> responseObservable =
mReportsService.createReport(report);
AndroidObservable.bindFragment(this, responseObservable)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<CreateReportResponse>() {
@Override
public void onCompleted() {
Log.d(getClass().getName(), "Completed createReport");
}
@Override
public void onError(Throwable e) {
Log.e(getClass().getName(), e.getMessage());
}
@Override
public void onNext(CreateReportResponse createReportResponse) {
Log.d(getClass().getName(), createReportResponse.toString());
}
});
} This produces the following an
When I remove OkHttp from
I also removed all configuration such as I was able to reproduce this on a Nexus 5 (Android 5.0.1), Moto G 2nd Edition (Android 4.4.4), Samsung Galaxy S4 (Android 4.4.2). I use this SimpleHTTPServer to test the POST requests. The server receives the following:
|
Can you reproduce this reliably? What does your server return? |
@johnjohndoe your simplehttpserver.py program is broken, and OkHttp is correct to fail on responses returned from it. You can see it by hitting the server with curl, which will also fail.
|
Oh, my fault - sorry. I just picked it up yesterday. I also tried Can you recommend another simple server which allows quick testing of HTTP requests? |
I got this issue sometimes on Andorid 2.3.4. interface:
gist: https://gist.github.com/edwardaa/443bb10abf2b812a9363
|
@swankjesse Thanks for the hint - I will come back if I still experience problems. (I am still fighting to set MockWebServer up in my project.) |
In order to reduce the split-brain problem this bug is causing I am locking this issue version in favor of OkHttp's @ square/okhttp#1114. |
Gist: https://gist.github.com/mazurio/8750846
Description is a text taken from TextView (Android), if it contains more than one new line then it causes EOFException and insert fails. Trying to figure it out now.
I tried to escape the string. It is the same problem.
The text was updated successfully, but these errors were encountered: