-
Notifications
You must be signed in to change notification settings - Fork 450
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
uploadAndFinish() hangs with no Internet when using OkHttp3Requestor #78
Comments
Thanks for the report! I can't seem to reproduce this though. (I'm getting exceptions thrown for both file uploads when attempting this offline.) What versions of the Dropbox and OkHttp libraries do you have installed? Also, can you add some logging, such as for the exceptions in your |
Sorry, I was trying to represent what I thought was causing the issue into a simple example, but I might have over simplified it. The bottom line is that in whatever situation I'm in, when I use the I'm using Dropbox 2.1.2 and OkHttp 3.4.1. As an aside, are there significant advantages to using the |
Thanks! I just tried again with those specific versions and I still can't reproduce it with this code, so please do let us know if you can track that down. And yes, it's up to you. For example, you may want to use OkHttp if your app already uses it for other HTTP use anyway, etc. |
The OkHttp requestors have to do some concurrency magic to allow streaming uploads. Whenever you call uploadAndFinish(in), a request is issued asynchronously through OkHttp with an empty PipedInputStream as the body. Then we copy over bytes from your input stream into the corresponding PipedOutputStream and register an asynchronous callback that allows us to wait for the request to finish. This way we don't have to buffer all bytes in memory before issuing the request. To figure out what's going on, you should take a thread dump when the request hangs so we know where the threads are blocked. You can use the JDK
My guess is that it's blocking on writes to the PipedOutputStream. Those writes are blocking if we filled up the 5MiB internal buffer for the piped stream. So if the OkHttp thread reading from the pipe died and didn't properly close the stream (or an exception was thrown during stream close), the writes could be hanging. |
@greg-db When you attempt to reproduce, make sure you use a file that's larger than 5MiB. |
Thanks for the tip Karl! I can now reproduce this using a single upload of a file larger than 5MiB. We'll look into it. |
This should be fixed in v3.0.4. |
@greg-db @wclausen @joshafeinberg @lchen8 A simple program using To prevent hanging use the following to close okHttpClient.dispatcher().executorService().shutdown();
okHttpClient.connectionPool().evictAll(); Footnotes |
@atkawa7 Thanks for the report! We'll look into it. |
@atkawa7 thanks for the report. For the default settings on @greg-db also repro'd a similar issue without any requests inflight (possibly this), so this is not limited to TL;DR; if you need an immediate shutdown, configure the requestor with your own dispatcher and connection pool. Adding some relevant links: |
@eyousefi Thanks for the suggestions. Whilst the default |
In the sample code below, when no Internet connection is present and using
OkHttp3Requestor
, the first upload throws an exception (as expected), but the second upload never returns fromuploadAndFinish()
.It seems as if once OkHttp throws an exception when it can't connect to the host, any subsequent request just hangs indefinitely.
This behavior does not occur when using the
StandardHttpRequestor
(instead, both upload operations throw an exception as expected).The text was updated successfully, but these errors were encountered: