Prevent hanging when deleting Docker builder container after exception

An exception being thrown while the Maven plugin is uploading the app
archive bits to an ephemeral builder container would leave the
interaction with the Docker daemon in a state that caused further
interaction with the daemon (such as deleting the ephemeral builder)
to hang indefinitely. This commit cleans up the connection on an
exception to prevent this condition.

Fixes gh-27515
This commit is contained in:
Scott Frederick
2021-07-30 12:24:28 -05:00
parent 7eb5f35f2f
commit 5d793afcb5
7 changed files with 162 additions and 1 deletions

View File

@@ -390,7 +390,13 @@ public class BuildImageMojo extends AbstractPackagerMojo {
public void writeTo(OutputStream outputStream) throws IOException {
TarArchiveOutputStream tar = new TarArchiveOutputStream(outputStream);
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
this.packager.packageImage(this.libraries, (entry, entryWriter) -> write(entry, entryWriter, tar));
try {
this.packager.packageImage(this.libraries, (entry, entryWriter) -> write(entry, entryWriter, tar));
}
catch (RuntimeException ex) {
outputStream.close();
throw new RuntimeException("Error packaging archive for image", ex);
}
}
private void write(ZipEntry jarEntry, EntryWriter entryWriter, TarArchiveOutputStream tar) {