Skip to content

Commit ec4207a

Browse files
Catch exceptions during AWS resource cleanup
1 parent 6125f56 commit ec4207a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

org-code-javabuilder/lib/src/main/java/org/code/javabuilder/AWSSystemExitHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.logging.Handler;
99
import java.util.logging.Logger;
1010
import org.code.protocol.JavabuilderContext;
11+
import org.code.protocol.JavabuilderThrowableMessageUtils;
1112

1213
public class AWSSystemExitHelper implements SystemExitHelper {
1314
private final String connectionId;
@@ -37,6 +38,11 @@ private void cleanUpResources() {
3738
api.deleteConnection(deleteConnectionRequest);
3839
} catch (GoneException e) {
3940
// if the connection is already gone, we don't need to delete the connection.
41+
} catch (Exception e) {
42+
// Handle any other exceptions so that shut down proceeds normally. If this is an
43+
// IllegalStateException, it indicates that the connection was already shut down for
44+
// some reason.
45+
Logger.getLogger(MAIN_LOGGER).warning(JavabuilderThrowableMessageUtils.getLoggingString(e));
4046
}
4147
// clean up log handler to avoid duplicate logs in future runs.
4248
Handler[] allHandlers = Logger.getLogger(MAIN_LOGGER).getHandlers();

org-code-javabuilder/lib/src/main/java/org/code/javabuilder/LambdaRequestHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ private void cleanUpAWSResources(String connectionId, AmazonApiGatewayManagement
364364
api.deleteConnection(deleteConnectionRequest);
365365
} catch (GoneException e) {
366366
// if the connection is already gone, we don't need to delete the connection.
367+
} catch (Exception e) {
368+
// Handle any other exceptions so that shut down proceeds normally. If this is an
369+
// IllegalStateException, it indicates that the connection was already shut down for
370+
// some reason.
371+
Logger.getLogger(MAIN_LOGGER).warning(JavabuilderThrowableMessageUtils.getLoggingString(e));
367372
}
368373
// clean up log handler to avoid duplicate logs in future runs.
369374
Handler[] allHandlers = Logger.getLogger(MAIN_LOGGER).getHandlers();

0 commit comments

Comments
 (0)