Skip to content

Commit 6125f56

Browse files
Merge pull request #352 from code-dot-org/sanchit/connection-shut-down
Force recycle container if connection pool has been shut down
2 parents 3453cdf + c1ef077 commit 6125f56

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ private void sendMessageHelper(PostToConnectionRequest post) {
4444
this.api.postToConnection(post);
4545
} catch (GoneException e) {
4646
throw new InternalFacingRuntimeException(CONNECTION_TERMINATED, e);
47+
} catch (IllegalStateException e) {
48+
// Thrown when the API Gateway client has been unexpectedly shut down.
49+
// We are still actively investigating why this happens in the first place,
50+
// but this will make the container fail for all subsequent sessions, so it
51+
// should be recycled.
52+
throw new FatalError(FatalErrorKey.CONNECTION_POOL_SHUT_DOWN, e);
4753
}
4854
}
4955
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.code.javabuilder;
22

3-
import static org.code.javabuilder.LambdaErrorCodes.LOW_DISK_SPACE_ERROR_CODE;
4-
import static org.code.javabuilder.LambdaErrorCodes.TEMP_DIRECTORY_CLEANUP_ERROR_CODE;
3+
import static org.code.javabuilder.LambdaErrorCodes.*;
54

65
public enum FatalErrorKey {
76
LOW_DISK_SPACE(LOW_DISK_SPACE_ERROR_CODE),
8-
TEMP_DIRECTORY_CLEANUP_ERROR(TEMP_DIRECTORY_CLEANUP_ERROR_CODE);
7+
TEMP_DIRECTORY_CLEANUP_ERROR(TEMP_DIRECTORY_CLEANUP_ERROR_CODE),
8+
CONNECTION_POOL_SHUT_DOWN(CONNECTION_POOL_SHUT_DOWN_ERROR_CODE);
99

1010
private final int errorCode;
1111

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ private LambdaErrorCodes() {
88
public static final int TEMP_DIRECTORY_CLEANUP_ERROR_CODE = 10;
99
public static final int LOW_DISK_SPACE_ERROR_CODE = 50;
1010
public static final int OUT_OF_MEMORY_ERROR_CODE = 60;
11+
public static final int CONNECTION_POOL_SHUT_DOWN_ERROR_CODE = 70;
1112
}

org-code-javabuilder/lib/src/main/java/org/code/javabuilder/util/LambdaUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.logging.Logger;
77
import org.code.javabuilder.InternalFacingRuntimeException;
88
import org.code.protocol.ClientMessage;
9+
import org.code.protocol.JavabuilderThrowableMessageUtils;
910
import org.code.protocol.OutputAdapter;
1011

1112
public final class LambdaUtils {
@@ -33,7 +34,7 @@ public static void safelySendMessage(
3334
}
3435
} catch (Exception e) {
3536
// Catch any other exceptions here to prevent them from propagating.
36-
Logger.getLogger(MAIN_LOGGER).warning(e.getMessage());
37+
Logger.getLogger(MAIN_LOGGER).warning(JavabuilderThrowableMessageUtils.getLoggingString(e));
3738
}
3839
}
3940
}

0 commit comments

Comments
 (0)