Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nextInvocation could be null for certain exceptions #23

Open
frencojobs opened this issue Feb 4, 2021 · 1 comment · May be fixed by #24
Open

nextInvocation could be null for certain exceptions #23

frencojobs opened this issue Feb 4, 2021 · 1 comment · May be fixed by #24

Comments

@frencojobs
Copy link

frencojobs commented Feb 4, 2021

The runtime's invoke function contains an exception catcher while getting the next invocation from AWS API. It goes like this,

} 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.

// 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.

} on Exception catch (error, stacktrace) {
	if (nextInvocation != null) {
	      await _client.postInvocationError(
			  nextInvocation.requestId, InvocationError(error, stacktrace));
	}
}

I'll submit a PR.

frencojobs added a commit to frencojobs/aws-lambda-dart-runtime that referenced this issue Feb 4, 2021
@frencojobs frencojobs linked a pull request Feb 4, 2021 that will close this issue
@kmcgill88
Copy link

I've also experienced this before! Glad you found a fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants