Skip to content

Commit c613ec7

Browse files
committed
fixed dead lock, caused by upload exceptions
1 parent d8d5bd0 commit c613ec7

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

  • src/main/java/de/unirostock/sems/cbarchive/web/rest

src/main/java/de/unirostock/sems/cbarchive/web/rest/RestApi.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,9 @@ public Response createArchiveEntry( @PathParam("archive_id") String archiveId, @
874874
return buildErrorResponse(500, user, "Cannot read options string.");
875875
}
876876

877+
Archive archive = null;
877878
try {
878-
Archive archive = user.getArchive(archiveId);
879+
archive = user.getArchive(archiveId);
879880
List<Object> result = new LinkedList<Object>();
880881

881882
// adds ending slash
@@ -891,9 +892,9 @@ else if( !path.endsWith("/") )
891892
}
892893

893894
for( FormDataBodyPart file : files ) {
894-
895+
String fileName = null;
895896
try {
896-
String fileName = file.getFormDataContentDisposition().getFileName();
897+
fileName = file.getFormDataContentDisposition().getFileName();
897898
// remove leading slash
898899
if( fileName.startsWith("/") )
899900
fileName = fileName.substring(1);
@@ -1003,16 +1004,23 @@ else if( opt.contains("override") )
10031004
// add to result list
10041005
result.add( new ArchiveEntryDataholder(entry) );
10051006
}
1006-
catch (IOException e) {
1007+
catch (CombineArchiveWebException | IOException e) {
10071008
LOGGER.error(e, MessageFormat.format("Error while uploading/adding file to archive {0} in Workspace {1}", archiveId, user.getWorkingDir() ));
1008-
result.add( new ArchiveEntryUploadException(MessageFormat.format("Error while uploading/adding file to archive {0} in Workspace {1}", archiveId, user.getWorkingDir()), path) );
1009+
String message = e.getMessage();
1010+
if( message == null || message.isEmpty() )
1011+
message = MessageFormat.format("Error while uploading/adding file to archive {0} in Workspace {1}", archiveId, user.getWorkingDir());
1012+
1013+
result.add( new ArchiveEntryUploadException(message, path + fileName) );
10091014
continue;
10101015
}
10111016

10121017
}
10131018

1014-
// pack and close the archive
1015-
archive.packAndClose();
1019+
synchronized (archive) {
1020+
// pack and close the archive
1021+
archive.packAndClose();
1022+
archive = null;
1023+
}
10161024

10171025
// trigger quota update
10181026
QuotaManager.getInstance().updateWorkspace( user.getWorkspace() );
@@ -1023,6 +1031,14 @@ else if( opt.contains("override") )
10231031
} catch (CombineArchiveWebException | IOException | TransformerException e) {
10241032
LOGGER.error(e, MessageFormat.format("Error while uploading/adding file to archive {0} in Workspace {1}", archiveId, user.getWorkingDir() ));
10251033
return buildErrorResponse(500, user, "Error while uploading file: " + e.getMessage() );
1034+
} finally {
1035+
try {
1036+
if( archive != null )
1037+
archive.close();
1038+
}
1039+
catch (IOException e) {
1040+
LOGGER.error(e, "Final closing of archive caused exception");
1041+
}
10261042
}
10271043

10281044
}

0 commit comments

Comments
 (0)