Skip to content

download_episode buffers entire episode in memory and is untested #370

Description

@forkwright

Finding

download_episode buffers the full episode response body in memory via response.bytes().await before writing it to disk, and the function is never invoked by any test. The fetch.rs test module only constructs FetchResult enum values as data; the download path itself (file creation, write_all, returned byte count) is never exercised.

Evidence

crates/komide/src/fetch.rs:71

pub async fn download_episode(

The body is read whole at crates/komide/src/fetch.rs:82:

response.bytes()

No test file references download_episode; it is absent from all of komide's test modules.

Why this matters

Podcast episode files routinely run 50-300 MB. Buffering each one fully on the heap before writing means concurrent downloads multiply the process RAM footprint proportionally, an exhaustion vector on a memory-constrained handset. Independently, the correctness of the write path is unverified: a path-construction typo, a partial write from an interrupted future, or a zero-byte write would ship undetected because CI never calls the function, leaving user-facing content silently missing.

Desired correction

Replace response.bytes() with a streaming copy (tokio::io::copy between the response byte stream and the file) so the full body is never resident in memory. Add an integration test against a mock HTTP server (e.g. wiremock) that asserts (1) the file is created with the expected content and (2) the returned u64 equals the on-disk file size. Done when: download_episode no longer buffers the full body in memory and is exercised by at least one test.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions