Skip to content

Default example is not working#1

Description

@aleasims

I'm running a default example in an empty directory:

sam init && sam run

And I get this:

 TEST  Testing Example Test Suite ...
 TEST    It should respond to HTTP requests...馃槶: Runtime error: Failed to get URL: error sending request for url (http://127.0.0.1:8080/hello.txt) (line 8, position 5) in call to function 'fetch' @ 'example' (line 6, position 33) in closure call (line 4, position 5) (514us 898ns)
 TEST  Testing Example Test Suite failed! 馃槶 (1 tests failed out of 1) (545us 8ns)

It looks like caddy container is destroyed immediately after creation:

$ podman ps -a
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

I tried debugging by adding this line right after podman command execution:

let o = Command::new("podman").args(["logs", "caddy"]).output().await.unwrap();
println!("{}", String::from_utf8_lossy(&o.stdout));
println!("{}", String::from_utf8_lossy(&o.stderr));

and it became behaving completely unpredictable: sometimes the test succeeds, sometimes it fails with no obvious difference:

$ sam run

{"level":"warn","ts":1737733486.5284944,"logger":"admin","msg":"admin endpoint disabled"}
{"level":"warn","ts":1737733486.5285542,"logger":"http.auto_https","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"static","http_port":80}
{"level":"info","ts":1737733486.5286343,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0003ebb00"}
{"level":"warn","ts":1737733486.528772,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":80"}
{"level":"warn","ts":1737733486.528779,"logger":"http","msg":"HTTP/3 skipped because it requires TLS","network":"tcp","addr":":80"}
{"level":"info","ts":1737733486.5287817,"logger":"http.log","msg":"server running","name":"static","protocols":["h1","h2","h3"]}
{"level":"info","ts":1737733486.528789,"msg":"Caddy serving static files on :80"}
{"level":"info","ts":1737733486.5349355,"logger":"tls","msg":"cleaning storage unit","storage":"FileStorage:/data/caddy"}
{"level":"info","ts":1737733486.5373535,"logger":"tls","msg":"finished cleaning storage units"}

 TEST  Testing Example Test Suite ...
 TEST    It should respond to HTTP requests...馃槶 (4ms 96us 704ns)
 TEST      Expected valid response from server (failed)
 TEST  Testing Example Test Suite failed! 馃槶 (1 tests failed out of 1) (4ms 115us 914ns)
Error: Test("Test run failed with 1 failed assertions")

So it actually behaves completely randomly.

My setup:

$ rustc --version
rustc 1.84.0 (9fc6b4312 2025-01-07)
$ podman --version
podman version 5.3.2
$ uname -a
Linux alea-pc-arch 6.12.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 18 Jan 2025 02:26:57 +0000 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions