Skip to content

nextInvocation could be null for certain exceptions #23

Open
@frencojobs

Description

@frencojobs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions