8585 #[ cfg( debug_assertions) ]
8686 if req. parts . status . is_server_error ( ) {
8787 error ! ( "Lambda Runtime server returned an unexpected error" ) ;
88- return RuntimeApiResponseFuture :: Ready ( Some ( Err ( req. parts . status . to_string ( ) . into ( ) ) ) ) ;
88+ return RuntimeApiResponseFuture :: Ready ( Box :: new ( Some ( Err ( req. parts . status . to_string ( ) . into ( ) ) ) ) ) ;
8989 }
9090
9191 // Utility closure to propagate potential error from conditionally executed trace
@@ -98,22 +98,23 @@ where
9898 } ;
9999 if let Err ( err) = trace_fn ( ) {
100100 error ! ( error = ?err, "Failed to parse raw JSON event received from Lambda. The handler will not be called. Log at TRACE level to see the payload." ) ;
101- return RuntimeApiResponseFuture :: Ready ( Some ( Err ( err) ) ) ;
101+ return RuntimeApiResponseFuture :: Ready ( Box :: new ( Some ( Err ( err) ) ) ) ;
102102 } ;
103103
104104 let request_id = req. context . request_id . clone ( ) ;
105105 let lambda_event = match deserializer:: deserialize :: < EventPayload > ( & req. body , req. context ) {
106106 Ok ( lambda_event) => lambda_event,
107107 Err ( err) => match build_event_error_request ( & request_id, err) {
108- Ok ( request) => return RuntimeApiResponseFuture :: Ready ( Some ( Ok ( request) ) ) ,
108+ Ok ( request) => return RuntimeApiResponseFuture :: Ready ( Box :: new ( Some ( Ok ( request) ) ) ) ,
109109 Err ( err) => {
110110 error ! ( error = ?err, "failed to build error response for Lambda Runtime API" ) ;
111- return RuntimeApiResponseFuture :: Ready ( Some ( Err ( err) ) ) ;
111+ return RuntimeApiResponseFuture :: Ready ( Box :: new ( Some ( Err ( err) ) ) ) ;
112112 }
113113 } ,
114114 } ;
115115
116- // Once the handler input has been generated successfully, the
116+ // Once the handler input has been generated successfully, pass it through to inner services
117+ // allowing processing both before reaching the handler function and after the handler completes.
117118 let fut = self . inner . call ( lambda_event) ;
118119 RuntimeApiResponseFuture :: Future ( fut, request_id, PhantomData )
119120 }
@@ -141,7 +142,10 @@ pub enum RuntimeApiResponseFuture<F, Response, BufferedResponse, StreamingRespon
141142 StreamError ,
142143 ) > ,
143144 ) ,
144- Ready ( Option < Result < http:: Request < Body > , BoxError > > ) ,
145+ /// This variant is used in case the invocation fails to be processed into an event.
146+ /// We box it to avoid bloating the size of the more likely variant, which is
147+ /// the future that drives event processing.
148+ Ready ( Box < Option < Result < http:: Request < Body > , BoxError > > > ) ,
145149}
146150
147151impl < F , Response , BufferedResponse , StreamingResponse , StreamItem , StreamError > Future
0 commit comments