Skip to content

Cohttp_async's get seems to leak open connections #166

@yminsky

Description

@yminsky

The following code demonstrates the bad behavior. For some reason, it looks like the connections are never closed. (Also, it's possible that I'm just doing something wrong with the resource handling here.). The original example is from Paolo Donadeo, but I made it a bit simpler.

open Core.Std
open Async.Std
open Log.Global

let make_request () =
  let url = "http://google.com" in
  Cohttp_async.Client.get (Uri.of_string url)
  >>= fun (r, b) ->
  Cohttp_async.Body.to_string b
  >>| fun body_text ->
  info "RESPONSE BODY: %s [SNIP]" (String.slice body_text 0 37);
  let status = Cohttp.Response.status r in
  match status with
  | `OK -> ()
  | _ -> error "Unexpected reply. HTTP status was: %s"
           (Cohttp.Code.string_of_status status)

let main_loop () =
  info "Program starts";
  let rec loop n =
    info "======================================= Making request #%03d" n;
    make_request ()
    >>= fun () ->
    loop (n + 1) 
  in
  loop 1

let () = main_loop () |> Deferred.don't_wait_for
let () = never_returns (Scheduler.go ())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions