Skip to content

Commit

Permalink
remote: Failed blob upload should close file handle.
Browse files Browse the repository at this point in the history
Two cases:
 - The upload succeeds and the Chunker consumes all its data and closes
 the underlying data source.
 - The upload fails and the Chunker doesn't close the data source, and
 so we call reset() manually.

RELNOTES: None.
PiperOrigin-RevId: 162178032
  • Loading branch information
buchgr committed Jul 17, 2017
1 parent 5dc2383 commit 9a45f55
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;

Expand All @@ -59,6 +61,8 @@
*/
final class ByteStreamUploader {

private static final Logger logger = Logger.getLogger(ByteStreamUploader.class.getName());

private final String instanceName;
private final Channel channel;
private final CallCredentials callCredentials;
Expand Down Expand Up @@ -389,7 +393,16 @@ public void onReady() {

call.sendMessage(request);
} catch (IOException e) {
call.cancel("Failed to read next chunk.", e);
try {
chunker.reset();
} catch (IOException e1) {
// This exception indicates that closing the underlying input stream failed.
// We don't expect this to ever happen, but don't want to swallow the exception
// completely.
logger.log(Level.WARNING, "Chunker failed closing data source.", e1);
} finally {
call.cancel("Failed to read next chunk.", e);
}
}
}
}
Expand Down

0 comments on commit 9a45f55

Please sign in to comment.