awslabs / awslabs/aws-lambda-dart-runtime
`nextInvocation` could be null for certain exceptions
- Dominant language
- Dart
- Stars
- 152
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
The runtime's `invoke` function contains an exception catcher while getting the next invocation from AWS API. It goes like this,
```dart
} on Exception catch (error, stacktrace) {
await _client.postInvocationError(
nextInvocation.requestId, InvocationError(error, stacktrace));
}
```
The code assumes that `nextInvocation` is never null and contains the `requestId`. But there are certain sceranios where the `nextInvocation` is null. One of them is when the HTTP request inside the `_client.getInvocation` function throws an `HttpException: Connection closed before full header was received` exception.
```dart
// inside invoke function's try closure
nextInvocation = await _client.getNextInvocation();
// inside the `getNextInvocation` function
final request = await _client.getUrl(Uri.parse(
'http://${runtimeApi}/${runtimeApiVersion}/runtime/invocation/next'));
final response = await request.close();
return NextInvocation.fromResponse(response);
```
The error is reproducible and happens on multiple & regular occasions. When it happens, the `requestId` is being called on null and throws a process exception and never ends the request. But it could be easily solved by checking whether the `nextInvocation` is null or not.
```dart
} on Exception catch (error, stacktrace) {
if (nextInvocation != null) {
await _client.postInvocationError(
nextInvocation.requestId, InvocationError(error, stacktrace));
}
}
```
I'll submit a PR.
Contributor guide
Assessment
This issue has not been assessed yet.