Skip to content

Cohttp-eio: response body not flushed? #1004

@smondet

Description

@smondet

Using the current master branch.

I have server code that hangs with:

Server.respond_string ~body:"Not found, sorry" ~status:`Not_found ()

"hangs" = curl client hangs, the ~stop argument of the server (the _ Promise.t) does not stop the server but the server logs show that it can handle more than one request.

It seems better with:

    Server.respond
      ~body:(Eio.Flow.string_source "Not found, sorry")
      ~status:`Not_found ()

"better = at least the client is "unlocked" and the ~stop argument (the _ Promise.t) does it's job. But the body is not actually transmitted.

It seems that this loop in cohttp-eio/src/utils.ml exits before sending any bytes:

let flow_to_writer flow writer write_body =
  let input = Eio.Buf_read.of_flow ~max_size:max_int flow in
  let rec loop () =
    let () =
      let () = Eio.Buf_read.ensure input 1 in
      let contents = Eio.Buf_read.(take (buffered_bytes input) input) in
      let () =
        Logs.debug (fun m -> m "send %d bytes of body" (String.length contents))
      in
      write_body writer contents
    in
    loop ()
  in
  try loop ()
  with End_of_file ->
    let () = Logs.debug (fun m -> m "end of outbound body") in
    ()

This is the debug output (in both cases of ~body: argument):

main.exe: [DEBUG] send headers
main.exe: [DEBUG] send body
main.exe: [DEBUG] end of outbound body

Any ideas?

(Eio 0.13, OCaml 5.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions