okhttp3 FLOW_CONTROL_ERROR - android

I am uploading .mp4 video using Retrofit 2.1.0 and OKHTTP 3.6.0. On some videos, I am having this exception. The timeout is set to 30 sec.
okhttp3.internal.http2.StreamResetException: stream was reset: FLOW_CONTROL_ERROR
W/System.err: at okhttp3.internal.http2.Http2Stream.checkOutNotClosed(Http2Stream.java:567)
W/System.err: at okhttp3.internal.http2.Http2Stream$FramingSink.emitFrame(Http2Stream.java:501)
W/System.err: at okhttp3.internal.http2.Http2Stream$FramingSink.write(Http2Stream.java:481)
W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:171)
W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:91)

Related

OkHttp ResponseBody.string() throws SocketTimeoutException

My server response looks like this:
HTTP/1.1 500 Internal server error
Date: Mon, 24 Oct 2022 10:37:05 GMT
Connection: keep-alive
I have no content in response, except headers.
I call chain.proceed(chain.request()).body()!!.string() inside my Interceptor and after some time of waiting .string() method throws SocketTimeoutException (However I expected to get an empty string there):
java.net.SocketTimeoutException: timeout
W/System.err: at okio.SocketAsyncTimeout.newTimeoutException(JvmOkio.kt:146)
W/System.err: at okio.AsyncTimeout.access$newTimeoutException(AsyncTimeout.kt:158)
W/System.err: at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:337)
W/System.err: at okio.RealBufferedSource.read(RealBufferedSource.kt:189)
W/System.err: at okhttp3.internal.http1.Http1ExchangeCodec$AbstractSource.read(Http1ExchangeCodec.java:389)
W/System.err: at okhttp3.internal.http1.Http1ExchangeCodec$UnknownLengthSource.read(Http1ExchangeCodec.java:529)
W/System.err: at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286)
W/System.err: at okio.RealBufferedSource.read(RealBufferedSource.kt:189)
W/System.err: at com.chuckerteam.chucker.internal.support.TeeSource.read(TeeSource.kt:24)
W/System.err: at okio.RealBufferedSource.select(RealBufferedSource.kt:229)
W/System.err: at okhttp3.internal.Util.bomAwareCharset(Util.java:467)
W/System.err: at okhttp3.ResponseBody.string(ResponseBody.java:181)
W/System.err: at ServerErrorConverter.getResponseContent(ServerErrorConverter.kt:156)
I can't find the reason for that behaviour and/or how to fix it. The only what I've found was that if my response contains Content-Length: 0 header, everything works OK.

FTPConnectionClosedException: Connection closed without indication on Android Device

I am trying to upload an image captured by camera to FTP server, I am using FTPClient object, and it is working successfully when running the Java code on computer, but it fails when running the code on an android device.
I have checked the INTERNET permission, also internet connection is stable, also the other internet related functions are working correctly, only this ftp client is not working.
Here is the code:
FTPClient ftpClient = new FTPClient();
ftpClient.connect("ftp.mywebsite.com",21);
Please note that mywebsite is just a place holder.
It is throwing the following FTPConnectionClosedException exception
W/System.err: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
W/System.err: at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:324)
W/System.err: at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:300)
W/System.err: at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:425)
W/System.err: at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:962)
W/System.err: at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:950)
W/System.err: at org.apache.commons.net.SocketClient._connect(SocketClient.java:244)
W/System.err: at org.apache.commons.net.SocketClient.connect(SocketClient.java:202)
W/System.err: at com.basma.basma_rider.Helper$3.doInBackground(Helper.java:367)
W/System.err: at com.basma.basma_rider.Helper$3.doInBackground(Helper.java:342)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err: at java.lang.Thread.run(Thread.java:841)

Can not load data from webservice from the first time

After getting facebook access token, i use it for login in my own web server. However in the first time, there is warning in the log file, and i can not load data from my server, but when i open app from second times, it load normally.
Below is warning log:
W/System.err: com.google.gson.JsonSyntaxException:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
at line 1 column 1 path $ W/System.err: at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
W/System.err: at
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
W/System.err: at
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
W/System.err: at
retrofit2.ServiceMethod.toResponse(ServiceMethod.java:122)
W/System.err: at
retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:217) W/System.err:
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180) W/System.err:
at
retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42) W/System.err: at
io.reactivex.Observable.subscribe(Observable.java:12084) W/System.err:
at
retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
W/System.err: at
io.reactivex.Observable.subscribe(Observable.java:12084) W/System.err:
at
io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
W/System.err: at io.reactivex.Single.subscribe(Single.java:3433)
W/System.err: at
io.reactivex.internal.operators.single.SingleDoOnSuccess.subscribeActual(SingleDoOnSuccess.java:35)
W/System.err: at io.reactivex.Single.subscribe(Single.java:3433)
W/System.err: at
io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
W/System.err: at
io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:579)
W/System.err: at
io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
W/System.err: at
io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
W/System.err: at
java.util.concurrent.FutureTask.run(FutureTask.java:266) W/System.err:
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W/System.err: at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err: at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err: at java.lang.Thread.run(Thread.java:764)
W/System.err: Caused by: java.lang.IllegalStateException: Expected
BEGIN_OBJECT but was STRING at line 1 column 1 path $ W/System.err:
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
W/System.err: at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213)
What could be causing this?
That error tells you that there is an error when GSON tries to parse the JSON returned by the web service you're calling. In particular, GSON is expecting a JSON object, but it receives a string (see the first line of the error message).
If the error happens only the first time you call it and not the second it means that the web service returns 2 different answers, and GSON can correctly parse the second one, but not the first one.
In order to find out what's wrong, you should provide more details, like your data model and the 2 responses returned by the web service.

Volley SSL error when uploading a file larger than 1mb (I/O error during system call, Connection reset by peer)

I tried adding a retry policy (https://stackoverflow.com/a/22169775/2098493)
but the error persist when file being uploaded is larger than 1mb.
W/System.err: com.android.volley.NoConnectionError: javax.net.ssl.SSLException: Write error: ssl=0xafc3fe00: I/O error during system call, Connection reset by peer
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:151)
W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
W/System.err: Caused by: javax.net.ssl.SSLException: Write error: ssl=0xafc3fe00: I/O error during system call, Connection reset by peer
W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:765)
W/System.err: at com.android.okio.Okio$1.write(Okio.java:70)
W/System.err: at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)
W/System.err: at com.android.okio.RealBufferedSink.write(RealBufferedSink.java:44)
W/System.err: at com.android.okhttp.internal.http.RetryableSink.writeToSocket(RetryableSink.java:77)
W/System.err: at com.android.okhttp.internal.http.HttpConnection.writeRequestBody(HttpConnection.java:240)
W/System.err: at com.android.okhttp.internal.http.HttpTransport.writeRequestBody(HttpTransport.java:77)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:622)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:500)
W/System.err: at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
W/System.err: at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110)
W/System.err: at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
Thanks for your advice.
The solution was a combination of adding Volley Retry Policy and making sure back-end and server (nodejs/nginx) max uploaded file size are both set correctly.
//where RETRY_DEFAULT_TIMEOUT_MS = 5000, RETRY_DEFAULT_MAX_RETRIES = 3, RETRY_DEFAULT_BACKOFF_MULT = 2.0f
request.setRetryPolicy(new DefaultRetryPolicy(RETRY_DEFAULT_TIMEOUT_MS,
RETRY_DEFAULT_MAX_RETRIES,
RETRY_DEFAULT_BACKOFF_MULT));

SSL Error during Facebook Login in Android

I am implementing Facebook Login in my App but its not working on Api 2.3.6
I have tested the App in Emulator and its working Fine upto Api 23
Also it's working in Device with API 21 but not in 2.3.6
The Error is related to SSL
Bcoz I have read in an SO answer that,
in Api level 2.3.6 all connections and authorizations are handled by HTTPS only
while in Api levels above 2.3.6 its not the HTTPS that does every task
Also I have noticed that whenever I am trying to call any URL starting
with HTTPS it's not giving the final result but gets silently stopped as was the case
with Googles Direction Api.
Below is the StackTrace I am getting in 2.3.6 :
V/webkit: LoadListener.handleSslErrorRequest():
url:https://m.facebook.com/v2.4/dialog/oauth?
return_scopes=true&response_type=token%2Csigned_request&redirect_uri
=fbconnect%3A%2F%2Fsuccess&display=touch&sdk=android-
4.5.1&e2e=%7B%22init%22%1232%7D&client_id=1234&default_audience=friends
primary error: 3 certificate: Issued to: CN=*.facebook.com,O=Facebook\,
Inc.,L=Menlo Park,ST=CA,C=US;
Issued by: 1.2.840.113549.1.9.1=#1223,CN=Cyberoam SSL
CA_C016700030,OU=Cyberoam Certificate
Authority,O=Elitecore,L=Ahmedabad,ST=Gujarat,C=IN;
I/System.out: close [socket][/0.0.0.0:52994]
I/webkit/webview: WebView.stopLoading()
D/webkit/webview: WebView.stopLoading(): webcorethread is initialized
I/webkit/webview: WebView.stopLoading()
D/webkit/webview: WebView.stopLoading(): webcorethread is initialized
W/System.err: at
com.facebook.login.LoginManager.onActivityResult(LoginManager.java:173)
W/System.err: at
com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:139)
W/System.err: at
com.facebook.internal.CallbackManagerImpl.onActivityResult
(CallbackManagerImpl.java:82)
W/System.err: at
com.hogo.integrationapp.FirstActivity.onActivityResult
(FirstActivity.java:179)
W/System.err: at
android.app.Activity.dispatchActivityResult(Activity.java:3975)
W/System.err: at
android.app.ActivityThread.deliverResults(ActivityThread.java:2629)
W/System.err: at
android.app.ActivityThread.handleSendResult(ActivityThread.java:2675)
W/System.err: at
android.app.ActivityThread.access$2000(ActivityThread.java:156)
W/System.err: at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1030)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:130)
W/System.err: at android.os.Looper.loop(SourceFile:351)
W/System.err: at
android.app.ActivityThread.main(ActivityThread.java:3821)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:538)
W/System.err: at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run\
(ZygoteInit.java:969)
W/System.err: at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
Is there any Easy way to solve it ?
Also I want to understand why this is happening ?
I am using Facebook Sdk 4.5.1
For API 4.4.2 :
The Error was due to a File Transfer App open in my Device, when i closed it the error was gone
Thanks in Advance...

Categories

Resources