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

Extension registration fails with Error("EOF while parsing a value", line: 1, column: 0) #922

Closed
bassmanitram opened this issue Sep 5, 2024 · 4 comments · Fixed by cargo-lambda/cargo-lambda#690

Comments

@bassmanitram
Copy link
Contributor

bassmanitram commented Sep 5, 2024

I have the simplest possible generic extension designed to be run from a script so the script doesn't need to mess with the whole registration protocol via curl etc.

My original script (which does mess with curl) works well with the cargo lambda watch --only-lambda-apis -a 127.0.0.1 -p 2807 test runtime server.

Running this program, however, appears to get just about all the way through registration but then terminates with Error("EOF while parsing a value", line: 1, column: 0) - looks very JSON issue-y to me :).

The source is:

use std::env;
use lambda_extension::{service_fn, Error, Extension, LambdaEvent, NextEvent};
use tracing_subscriber::EnvFilter;

async fn handle(event: LambdaEvent) -> Result<(), Error> {
    match event.next {
        NextEvent::Shutdown(_e) => {
            // do nothing specific with the shutdown event
        }
        NextEvent::Invoke(_e) => {
            // do nothing specific with the invoke event - which we don't even register for
        }
    }
    Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())       
        .without_time()
        .with_ansi(false)
        .init();
    let mut args = env::args();
    args.next(); //lose the program name
    let extension_name = args.next().expect("First argument must be the extension name");
    Extension::new()
        .with_extension_name(&extension_name)
        .with_events_processor(service_fn(handle))
        .with_events(&["SHUTDOWN"])
        .register().await
        .expect("registration failed")
        .run().await
}

Note that I am building this with cargo build not cargo lambda build --extension because I'm building the Extension.

The intended use is something like this as the actual extensions script (that's simplistic, of course, but you get the idea I hope);

real-functionality.sh &
PID=$!
the-above-program my-extension-name
kill $PID
wait $PID

This works in the real Lambda service.

Trace logs:

@bassmanitram
Copy link
Contributor Author

bassmanitram commented Sep 5, 2024

Capturing the request response flow...

REQUEST: Request { method: POST, uri: /.rt/2020-01-01/extension/register, version: HTTP/1.1, headers: {"user-agent": "aws-lambda-rust/0.11.1", "lambda-extension-name": "test-extension", "lambda-extension-accept-feature": "accountId", "content-type": "application/json", "host": "127.0.0.1:2807", "content-length": "23"}, body: Body(Streaming) }
RESPONSE: Response { status: 200, version: HTTP/1.1, headers: {"lambda-extension-identifier": "7cc1236c-b570-4cb8-bab1-924e7dbf0cd6", "content-length": "0", "date": "Thu, 05 Sep 2024 13:46:32 GMT"}, body: Body(Empty) }

Looks like the client is trying to parse JSON from an empty body, though I can't make it work even if I hack the response to 204 or replace the response body with valid JSON.

@calavera
Copy link
Contributor

calavera commented Sep 7, 2024

This is a bug in Cargo Lambda. cargo-lambda/cargo-lambda#690 fixes the problem.

Copy link

github-actions bot commented Sep 7, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.

@bassmanitram
Copy link
Contributor Author

Perfect - Thx

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