{"id":"ebb16fc560eb6e82","repo":"hyperium/hyper","slug":"user-body-write-aborted","errorCode":null,"errorMessage":"user body write aborted","messagePattern":"user body write aborted","errorType":"exception","errorClass":"hyper::Error","httpStatus":null,"severity":"error","filePath":"src/error.rs","lineNumber":422,"sourceCode":"    ))]\n    pub(super) fn new_body<E: Into<Cause>>(cause: E) -> Error {\n        Error::new(Kind::Body).with(cause)\n    }\n\n    #[cfg(all(\n        any(feature = \"client\", feature = \"server\"),\n        any(feature = \"http1\", feature = \"http2\")\n    ))]\n    pub(super) fn new_body_write<E: Into<Cause>>(cause: E) -> Error {\n        Error::new(Kind::BodyWrite).with(cause)\n    }\n\n    #[cfg(any(\n        all(feature = \"http1\", any(feature = \"client\", feature = \"server\")),\n        feature = \"ffi\"\n    ))]\n    pub(super) fn new_body_write_aborted() -> Error {\n        Error::new(Kind::User(User::BodyWriteAborted))\n    }\n\n    fn new_user(user: User) -> Error {\n        Error::new(Kind::User(user))\n    }\n\n    #[cfg(any(feature = \"http1\", feature = \"http2\"))]\n    #[cfg(feature = \"server\")]\n    pub(super) fn new_user_header() -> Error {\n        Error::new_user(User::UnexpectedHeader)\n    }\n\n    #[cfg(all(feature = \"http1\", feature = \"server\"))]\n    pub(super) fn new_header_timeout() -> Error {\n        Error::new(Kind::HeaderTimeout)\n    }\n\n    #[cfg(feature = \"http1\")]","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/hyperium/hyper/blob/084473f728f9d07b3be5845475aa2f62ed9ff579/src/error.rs#L404-L440","documentation":"Thrown via Error::new_body_write_aborted() (src/error.rs:422, Kind::User(User::BodyWriteAborted)). It means the outgoing body write was explicitly aborted before completion — hyper's internal state machine detected the user side gave up on writing the response/request body. Detect with Error::is_body_write_aborted(). Produced at proto/h1/conn.rs:808 with the parser 'not_eof' note, and via body/incoming.rs:438 send_error.","triggerScenarios":"A Server drops the Body sender / returns an error that aborts the in-progress response body (conn.rs:808 attaches the not_eof cause); the body channel's send_error is called with this error (incoming.rs:438); an FFI/aborted callback cancels the write. The peer then sees a truncated body.","commonSituations":"A handler panics or returns early while streaming a response; a service intentionally aborts a response (e.g. after deciding to send an error); an FFI user callback aborted the operation; the body producer was dropped mid-stream.","solutions":["If the abort was intentional, this is expected — ensure the peer can tolerate a truncated body or send a proper error status before aborting.","If unexpected, audit the handler/body-producer for early returns, panics, or dropped senders.","Guard body producers so they complete normally (send trailing data / close cleanly) unless you deliberately abort."],"exampleFix":"// before: handler returns early, aborting the response body mid-stream\nasync fn handler(req: Request<Body>) -> Result<Response<Body>, Infallible> {\n    if !authorized(&req) {\n        return Ok(Response::builder().status(403).body(Body::empty()).unwrap());\n        // any previously started streaming body is aborted\n    }\n    /* ... */\n}\n\n// after: decide before starting the stream, or complete it cleanly\nasync fn handler(req: Request<Body>) -> Result<Response<Body>, Infallible> {\n    if !authorized(&req) {\n        return Ok(Response::builder().status(403).body(Body::empty()).unwrap());\n    }\n    Ok(Response::new(stream_body().await))\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_body_write_aborted(err: &hyper::Error) -> bool {\n    err.is_body_write_aborted()\n}","tryCatchPattern":"if let Err(e) = serve_connection(...).await {\n    if e.is_body_write_aborted() {\n        tracing::warn!(\"response body was aborted before completion\");\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Avoid early returns/panics inside handlers that have already started streaming a body.","Send a proper error status before aborting if you must stop a response.","Keep FFI callbacks and body producers from aborting except on explicit user intent."],"tags":["body","write","abort","ffi","rust"],"analyzedSha":"084473f728f9d07b3be5845475aa2f62ed9ff579","analyzedAt":"2026-08-06T01:20:18.522Z","schemaVersion":2}