okhttp: okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR/ CANCEL
I am connecting to web service with last version retrofit
but get me bellow error :
okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR
My code is like bellow :
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.
build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://xxx")
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.build();
final PublicApi request = retrofit.create(PublicApi.class);
Call<GetStatusSaveContactListModel> call = request.sendContactLists("saveContactList", obj.toString());
call.enqueue(new Callback<GetStatusSaveContactListModel>() {
@Override
public void onResponse(@NonNull Call<GetStatusSaveContactListModel> call, @NonNull Response<GetStatusSaveContactListModel> response) {
}
@Override
public void onFailure(@NonNull Call<GetStatusSaveContactListModel> call, Throwable t) {
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
And
@POST("/web_service/mobile/rest")
Call<GetStatusSaveContactListModel> sendContactLists(@Query("function") String function,
@Query("data") String data);
And
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 6
- Comments: 54 (3 by maintainers)
Commits related to this issue
- disable http/2 & connection pooling Work around for https://github.com/square/okhttp/issues/3955 — committed to spotify/styx by deleted user 6 years ago
- disable http/2 & connection pooling Work around for https://github.com/square/okhttp/issues/3955 — committed to spotify/styx by deleted user 6 years ago
- disable http/2 Work around for https://github.com/square/okhttp/issues/3955 — committed to spotify/styx by deleted user 6 years ago
- disable http/2 for connection to k8s (looks like https://github.com/square/okhttp/issues/3955) — committed to JetBrains/teamcity-kubernetes-plugin by deleted user 4 years ago
httpClient.protocols( Collections.singletonList(Protocol.HTTP_1_1) );
This what worked for me. https://stackoverflow.com/questions/53648852/how-to-solve-okhttp3-internal-http2-streamresetexception-stream-was-reset-refuThis is happening to me in production, but I am not able to reproduce the problem when debugging
Have we got any update on this? I get this when i trigger a specific api in quick succession for example: API called API called again (before i could get response) throws StreamResetException
but if i call the API wait for some time i get the response API called . . . waiting . . after some waiting finally i get the response
@shrutigupta23 In theory now, all that should be required to enable framelogging via adb is the following
we are having the same issue.
I’m guessing you mean something that’s described here: https://www.twilio.com/blog/2017/10/http2-issues.html?
@mlazowik Yep - I’m assuming your case may possibly be the one I mentioned above “Or head of line blocking causing a bunch of later requests to be delayed while HTTP/1.1 may allow small requests to succeed.”
@LouisCAD Thanks, but I’m not using cacel() in my code, it happens always when there is bad connection.