Skip to content

Improve HTTP parsing#110

Merged
slp merged 2 commits into
libkrun:mainfrom
slp:better-http-parsing
Jul 1, 2026
Merged

Improve HTTP parsing#110
slp merged 2 commits into
libkrun:mainfrom
slp:better-http-parsing

Conversation

@slp

@slp slp commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Instead of doing manual parsing of HTTP requests, rely on a mature crate like httparse to do the job. Also, actually parse the REST endpoint and contents to make sure we're acting on the right request.

Fixes: podman-container-tools/podman#29084

@slp slp marked this pull request as draft July 1, 2026 09:10
@slp slp force-pushed the better-http-parsing branch from 99518e8 to 866af48 Compare July 1, 2026 09:11
@slp slp marked this pull request as ready for review July 1, 2026 10:13

@Luap99 Luap99 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a maintainer of course but seems good to me overall, a lot better than just checking for POST

Comment thread src/status.rs
};

match state {
"Stop" | "HardStop" => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no hard shut down for libkrun implemented? I guess practically from my tests we could sigkill the process?

in podman so far we have a 90s timeout for a graceful shutdown and then make another request with HardStop, if the VM ever hung in shutdown this will not be able to kill it and we leak the VM.
(anyhow outside of the scope of this PR just found it weird we treat them the same)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't have a hard shut down yet. Both SIGTERM and SIGKILL are a bit dangerous as we risk leaving in-flight virtio-blk buffers unwritten.

In 2.0 we'll have a way to orderly exit the VMM without the guest cooperation.

Comment thread src/status.rs Outdated
)
}

fn parse_state_value(json: &str) -> Option<&str> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you want to avoid a json dep? I guess this is not fully spec compliant parsing either but likely gets the job good enough done.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but on a second thought, given that we already added httpparse, we could also add a popular JSON crate, like serde.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@slp slp force-pushed the better-http-parsing branch from f931d4b to ddec6b3 Compare July 1, 2026 11:10
slp added 2 commits July 1, 2026 13:11
Instead of doing manual parsing of HTTP requests, rely on a mature crate
like httparse to do the job. Also, actually parse the REST endpoint and
contents to make sure we're acting on the right request.

Fixes: podman-container-tools/podman#29084
Signed-off-by: Sergio Lopez <slp@redhat.com>
This is a patch release to include the fix in HTTP parsing.

Signed-off-by: Sergio Lopez <slp@redhat.com>
@slp slp force-pushed the better-http-parsing branch from ddec6b3 to 8a5fd30 Compare July 1, 2026 11:12

@lstocchi lstocchi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW LGTM

@slp slp merged commit c56c2b4 into libkrun:main Jul 1, 2026
3 checks passed
@slp slp deleted the better-http-parsing branch July 1, 2026 16:30
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 this pull request may close these issues.

libkrun: macOS resource limits cause periodic VM reboots (~every 60 min)

3 participants