Skip to content

Commit 73f265f

Browse files
Merge pull request #354 from code-dot-org/sanchit/catch-cleanup-exception
Catch exceptions during AWS resource cleanup
2 parents 56eadf3 + d976868 commit 73f265f

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
@@ -370,6 +370,11 @@ private void cleanUpAWSResources(String connectionId, AmazonApiGatewayManagement
370370
api.deleteConnection(deleteConnectionRequest);
371371
} catch (GoneException e) {
372372
// if the connection is already gone, we don't need to delete the connection.
373+
} catch (Exception e) {
374+
// Handle any other exceptions so that shut down proceeds normally. If this is an
375+
// IllegalStateException, it indicates that the connection was already shut down for
376+
// some reason.
377+
Logger.getLogger(MAIN_LOGGER).warning(JavabuilderThrowableMessageUtils.getLoggingString(e));
373378
}
374379
// clean up log handler to avoid duplicate logs in future runs.
375380
Handler[] allHandlers = Logger.getLogger(MAIN_LOGGER).getHandlers();

0 commit comments

Comments
 (0)