diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/GrpcReplicationClient.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/GrpcReplicationClient.java index 548d1147a7f2..91c74004beee 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/GrpcReplicationClient.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/GrpcReplicationClient.java @@ -161,7 +161,16 @@ public void onNext(CopyContainerResponseProto chunk) { try { chunk.getData().writeTo(stream); } catch (IOException e) { - response.completeExceptionally(e); + LOG.error("Failed to write the stream buffer to {} for container {}", + outputPath, containerId, e); + try { + stream.close(); + } catch (IOException ex) { + LOG.error("Failed to close OutputStream {}", outputPath, e); + } finally { + deleteOutputOnFailure(); + response.completeExceptionally(e); + } } } @@ -176,6 +185,7 @@ public void onError(Throwable throwable) { } catch (IOException e) { LOG.error("Failed to close {} for container {}", outputPath, containerId, e); + deleteOutputOnFailure(); response.completeExceptionally(e); } } @@ -189,9 +199,9 @@ public void onCompleted() { } catch (IOException e) { LOG.error("Downloaded container {} OK, but failed to close {}", containerId, outputPath, e); + deleteOutputOnFailure(); response.completeExceptionally(e); } - } private void deleteOutputOnFailure() { @@ -204,5 +214,4 @@ private void deleteOutputOnFailure() { } } } - }