8181public abstract class LambdaWrapper <ResourceT , CallbackT > implements RequestStreamHandler {
8282
8383 private static final List <Action > MUTATING_ACTIONS = Arrays .asList (Action .CREATE , Action .DELETE , Action .UPDATE );
84+ private static final int INVOCATION_TIMEOUT_MS = 60000 ;
8485
8586 protected final Serializer serializer ;
8687 protected LoggerProxy loggerProxy ;
@@ -557,8 +558,10 @@ private boolean scheduleReinvocation(final HandlerRequest<ResourceT, CallbackT>
557558 // has enough runtime (with 20% buffer), we can reschedule from a thread wait
558559 // otherwise we re-invoke through CloudWatchEvents which have a granularity of
559560 // minutes
560- if ((handlerResponse .getCallbackDelaySeconds () < 60 )
561- && (context .getRemainingTimeInMillis () / 1000d ) > handlerResponse .getCallbackDelaySeconds () * 1.2 ) {
561+ // This also guarantees a maximum of a minute of execution time per local
562+ // reinvocation
563+ if ((handlerResponse .getCallbackDelaySeconds () < 60 ) && context
564+ .getRemainingTimeInMillis () > Math .abs (handlerResponse .getCallbackDelaySeconds ()) * 1200 + INVOCATION_TIMEOUT_MS ) {
562565 log (String .format ("Scheduling re-invoke locally after %s seconds, with Context {%s}" ,
563566 handlerResponse .getCallbackDelaySeconds (), reinvocationContext .toString ()));
564567 sleepUninterruptibly (handlerResponse .getCallbackDelaySeconds (), TimeUnit .SECONDS );
@@ -567,7 +570,7 @@ private boolean scheduleReinvocation(final HandlerRequest<ResourceT, CallbackT>
567570
568571 log (String .format ("Scheduling re-invoke with Context {%s}" , reinvocationContext .toString ()));
569572 try {
570- int callbackDelayMinutes = handlerResponse .getCallbackDelaySeconds () / 60 ;
573+ int callbackDelayMinutes = Math . abs ( handlerResponse .getCallbackDelaySeconds () / 60 ) ;
571574 this .scheduler .rescheduleAfterMinutes (context .getInvokedFunctionArn (), callbackDelayMinutes , request );
572575 } catch (final Throwable e ) {
573576 this .log (String .format ("Failed to schedule re-invoke, caused by %s" , e .toString ()));
0 commit comments