diff --git a/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java b/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java index e8b8f313c54..855ee4e8f9d 100644 --- a/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java +++ b/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java @@ -96,8 +96,8 @@ private Future isSizeChanged() { private Future downloadFile() { return fileSystem.open(tmpPath, new OpenOptions()) .compose(tmpFile -> sendHttpRequest(getRequestOptions) - .compose(response -> response.pipeTo(tmpFile)) - .onComplete(result -> tmpFile.close())); + .onFailure(ignored -> tmpFile.close()) + .compose(response -> response.pipeTo(tmpFile))); } private Future sendHttpRequest(RequestOptions requestOptions) { diff --git a/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java b/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java index d60ff696ba7..076e03e0f03 100644 --- a/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java +++ b/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java @@ -125,6 +125,7 @@ public void getShouldReturnFailureOnNotOkStatusCode() { final Future result = target.get(); // then + verify(tmpFile).close(); FutureAssertion.assertThat(result).isFailed() .hasMessage("Got unexpected response from server with status code 204 and message null"); } @@ -147,7 +148,6 @@ public void getShouldReturnExpectedResult() { final Future result = target.get(); // then - verify(tmpFile).close(); assertThat(result.result()).isEqualTo(SAVE_PATH); } @@ -178,7 +178,6 @@ public void getShouldReturnExpectedResultWhenCheckRemoteFileSizeIsTrue() { final Future result = target.get(); // then - verify(tmpFile).close(); assertThat(result.result()).isEqualTo(SAVE_PATH); }