ocaml-cohttp icon indicating copy to clipboard operation
ocaml-cohttp copied to clipboard

Unix HTTP client "resolution failed: unknown scheme" if /etc/services is missing

Open bbc2 opened this issue 5 years ago • 14 comments

I made the following program:

let main =
  let%lwt _response =
    Cohttp_lwt_unix.Client.get (Uri.of_string "http://127.0.0.1:8000")
  in
  Lwt.return ()

let () =
  Lwt_main.run main

When I run it in an environment where the /etc/services file is missing, like the default Debian Docker image, it fails with the following message:

# ./main.exe 
Fatal error: exception (Failure "resolution failed: unknown scheme")

As far as I can tell, this is due to how Conduit resolves URLs with Lwt_unix.getservbyname.

Since Cohttp is an HTTP library, maybe it shouldn't depend on this database? Or maybe Lwt or Conduit should have an external dependency on netbase, the Debian package that provides the /etc/services file?

Versions used:

cohttp                  2.3.0
cohttp-lwt              2.3.0
cohttp-lwt-unix         2.3.0
conduit                 2.0.1
conduit-lwt             2.0.1
conduit-lwt-unix        2.0.1
lwt                     4.3.0
lwt_ppx                 1.2.3

bbc2 avatar Sep 24 '19 09:09 bbc2

Actually, never mind my suggestion on depext: it's a run-time issue, not a compile-time one.

bbc2 avatar Sep 24 '19 11:09 bbc2

+1 I experienced the same and when I added the file, the error message has been changed.

shogochiai avatar Nov 26 '19 02:11 shogochiai

Experienced same issue when working building another project. curl worked just fine. wget just fine. But using the URL through ocaml-cohttp failed "unknown scheme" until I added this file. Why is this file so critical? Why do other libraries/utilities not need this file?

utdrmac avatar Dec 10 '19 20:12 utdrmac

In my docker ubuntu builds apt install netbase creates an /etc/services file. (FYI)

utdrmac avatar Dec 10 '19 20:12 utdrmac

This should not be a problem from the next version of cohttp

mseri avatar Oct 22 '20 17:10 mseri

I'm hitting this again when running the tests for cohttp-lwt-unix in the nix build sandbox:

 test_parser alias cohttp-lwt-unix/test/runtest
..........
Ran: 10 tests in: 0.01 seconds.
OK
   test_body alias cohttp-lwt-unix/test/runtest
....
Ran: 4 tests in: 0.01 seconds.
OK
 test_sanity alias cohttp-lwt-unix/test/runtest (exit 1)
(cd _build/default/cohttp-lwt-unix/test && ./test_sanity.exe)
[DEBUG][application]: Cohttp debugging output is active
EEEEEEE
==============================================================================
Error: Cohttp Server Test:6:client_close

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:5:expert response

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:4:no leaks on requests

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:3:massive chunked

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:2:pipelined with interleaving requests

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:1:pipelined chunk test

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:0:sanity test

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
Ran: 7 tests in: 0.00 seconds.
FAILED: Cases: 7 Tried: 7 Errors: 7 Failures: 0 Skip:  0 Todo: 0 Timeouts: 0.
test_sanity_noisy alias cohttp-lwt-unix/test/runtest (exit 1)
(cd _build/default/cohttp-lwt-unix/test && ./test_sanity_noisy.exe)
[DEBUG][application]: Cohttp debugging output is active
EEE
==============================================================================
Error: Cohttp Server Test:2:unreadable file returns 500

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:1:no body when response is not modified

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
==============================================================================
Error: Cohttp Server Test:0:empty chunk test

(Failure "resolution failed: unknown scheme")
------------------------------------------------------------------------------
Ran: 3 tests in: 0.00 seconds.
FAILED: Cases: 3 Tried: 3 Errors: 3 Failures: 0 Skip:  0 Todo: 0 Timeouts: 0.

Any ideas? I'm having trouble debugging this as I don't know where this error message originates.

sternenseemann avatar May 01 '21 20:05 sternenseemann

I think this was resolved by conduit 3, since that has been pulled it is likely still an issue.

mseri avatar May 01 '21 21:05 mseri

Which versions of conduit and cohttp are you testing?

mseri avatar May 01 '21 21:05 mseri

4.0.0 for both packages.

sternenseemann avatar May 01 '21 21:05 sternenseemann

The culprit should be this call in conduit-lwt-unix mentioned in the report: https://github.com/mirage/ocaml-conduit/blob/a2f91d0fb17c9b0a8436dd39c4267b9144f0bdea/src/conduit-lwt-unix/resolver_lwt_unix.ml#L46

A temporary fix is to make sure you have the /etc/services file, I have asked to reopen the relative conduit issue as well

mseri avatar May 01 '21 21:05 mseri

Sorry to revive a dead thread, but in case anyone else has this issue I think it's worth sharing. This error will also be shown if you reach the kernel's open file limit, which would mean cohttp can't open /etc/services. Not sure if this is still the case since I'm using 4.x, though

zbaylin avatar Feb 23 '23 20:02 zbaylin

I hit the same issue today. I deployed a static binary that uses cohttp, in a "scratch" docker. I had to manually add /etc/services. This is using cohttp 5.3.1.

acieroid avatar Jan 31 '24 12:01 acieroid