Skip to content

Commit de73155

Browse files
committed
Another commit for #71. Looks like the awaitInitialization method needs to be called after the resources are defined
1 parent ab7160b commit de73155

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyRe
9393
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
9494
if (!initialized) {
9595
defineRoutes();
96+
// it's important to call the awaitInitialization method not to run into race
97+
// conditions as routes are loaded asynchronously
98+
Spark.awaitInitialization();
9699
initialized = true;
97100
}
98101
return handler.proxy(awsProxyRequest, context);

samples/spark/pet-store/src/main/java/com/amazonaws/serverless/sample/spark/LambdaHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.fasterxml.jackson.databind.ObjectMapper;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
27+
import spark.Spark;
2728

2829
import javax.ws.rs.core.Response;
2930
import java.util.UUID;
@@ -45,6 +46,7 @@ public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context c
4546
try {
4647
handler = SparkLambdaContainerHandler.getAwsProxyHandler();
4748
defineResources();
49+
Spark.awaitInitialization();
4850
} catch (ContainerInitializationException e) {
4951
log.error("Cannot initialize Spark application", e);
5052
return null;

0 commit comments

Comments
 (0)