85
85
#[ cfg( debug_assertions) ]
86
86
if req. parts . status . is_server_error ( ) {
87
87
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 ( ) ) ) ) ) ;
89
89
}
90
90
91
91
// Utility closure to propagate potential error from conditionally executed trace
@@ -98,22 +98,23 @@ where
98
98
} ;
99
99
if let Err ( err) = trace_fn ( ) {
100
100
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) ) ) ) ;
102
102
} ;
103
103
104
104
let request_id = req. context . request_id . clone ( ) ;
105
105
let lambda_event = match deserializer:: deserialize :: < EventPayload > ( & req. body , req. context ) {
106
106
Ok ( lambda_event) => lambda_event,
107
107
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) ) ) ) ,
109
109
Err ( err) => {
110
110
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) ) ) ) ;
112
112
}
113
113
} ,
114
114
} ;
115
115
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.
117
118
let fut = self . inner . call ( lambda_event) ;
118
119
RuntimeApiResponseFuture :: Future ( fut, request_id, PhantomData )
119
120
}
@@ -141,7 +142,10 @@ pub enum RuntimeApiResponseFuture<F, Response, BufferedResponse, StreamingRespon
141
142
StreamError ,
142
143
) > ,
143
144
) ,
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 > > > ) ,
145
149
}
146
150
147
151
impl < F , Response , BufferedResponse , StreamingResponse , StreamItem , StreamError > Future
0 commit comments