Browse files

Android. OkHttp crash fixed on upload re-try. (#20802)

This change fixes this issue:
Pull Request resolved: #20802

Differential Revision: D9478422

Pulled By: hramos

fbshipit-source-id: ce3a098a71c8f50a62b011a2a277004ab7a7b655
  • Loading branch information...
dryganets authored and kelset committed Aug 23, 2018
1 parent 9a4c21f commit 7a246e4872ec29a521216877ae5f5d26b5384a38
@@ -19,7 +19,6 @@
private final RequestBody mRequestBody;
private final ProgressListener mProgressListener;
private BufferedSink mBufferedSink;
private long mContentLength = 0L;
public ProgressRequestBody(RequestBody requestBody, ProgressListener progressListener) {
@@ -42,16 +41,17 @@ public long contentLength() throws IOException {
public void writeTo(BufferedSink sink) throws IOException {
if (mBufferedSink == null) {
mBufferedSink = Okio.buffer(outputStreamSink(sink));
// In 99% of cases, this method is called strictly once.
// The only case when it is called more than once is internal okhttp upload re-try.
// We need to re-create CountingOutputStream in this case as progress should be re-evaluated.
BufferedSink sinkWrapper = Okio.buffer(outputStreamSink(sink));
// contentLength changes for input streams, since we're using inputStream.available(),
// so get the length before writing to the sink
private Sink outputStreamSink(BufferedSink sink) {

0 comments on commit 7a246e4

Please sign in to comment.