Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behavior between nqsb-tls and openssl #97

Closed
smondet opened this issue Oct 22, 2015 · 4 comments
Closed

Different behavior between nqsb-tls and openssl #97

smondet opened this issue Oct 22, 2015 · 4 comments

Comments

@smondet
Copy link
Contributor

smondet commented Oct 22, 2015

Maybe I'm missing something obivous, but with CONDUIT_TLS=native the HTTP requests seems to be handled sequentially.

This is my server:

#use "topfind";;
#require "cohttp.lwt";;
let say fmt = Printf.(ksprintf (printf "%s\n%!") fmt)

let mode =
  let certfile = "_test_env/test-cert.pem" in
  let keyfile =  "_test_env/test-key.pem" in
  let port = 4242 in
  `TLS (
    (* `TLS means that conduit will do:
       match Sys.getenv "CONDUIT_TLS" with
       | "native" | "Native" | "NATIVE" -> Native
       | _ -> OpenSSL *)
    `Crt_file_path certfile,
    `Key_file_path keyfile,
    `No_password, `Port port)
open Lwt
let req_callback (_, conn_id) request body =
  let id = Cohttp.Connection.to_string conn_id in
  say "Connection %s, request %s" id
    (Cohttp.Request.sexp_of_t request |> Sexplib.Sexp.to_string);
  match Uri.path (Cohttp.Request.uri request) with
  | "/sleep" ->
    Lwt_unix.sleep 10.
    >>= fun () ->
    Cohttp_lwt_unix.Server.respond_string ~status:`OK  ~body:"slept" ()
  | other ->
    Cohttp_lwt_unix.Server.respond_string ~status:`OK  ~body:"hello" ()

let () =
  Lwt_main.run
    Cohttp_lwt_unix.Server.(
      create ~mode (make ~callback:req_callback ()))

OpenSSL

If I run CONDUIT_TLS=openssl ocaml server.ml

Then I can run curl -k https://127.0.0.1:4242/sleep on one terminal, and many times curl -k https://127.0.0.1:4242/hello on another terminal, everything is fine.

OCaml-TLS

When running CONDUIT_TLS=native ocaml server.ml, if I have curl -k https://127.0.0.1:4242/sleep on one shell, any call to curl -k https://127.0.0.1:4242/hello on another terminal will block until the /sleep is done.

@smondet
Copy link
Contributor Author

smondet commented Oct 22, 2015

All of this with conduit 0.9.0, cohttp 0.18.0, tls 0.6.0.

@smondet
Copy link
Contributor Author

smondet commented Dec 11, 2015

I just tried with the new TLS release and the lack of concurrency is still there:

$ ocamlfind list | egrep 'lwt|cohttp|tls'
cohttp              (version: 0.19.3)
cohttp.js           (version: 0.19.3)
cohttp.lwt          (version: 0.19.3)
cohttp.lwt-core     (version: 0.19.3)
cohttp.top          (version: 0.19.3)
conduit.lwt         (version: 0.9.0)
conduit.lwt-unix    (version: 0.9.0)
cstruct.lwt         (version: 1.7.0)
lwt                 (version: 2.5.1)
lwt.log             (version: 2.5.1)
lwt.ppx             (version: 2.5.1)
lwt.preemptive      (version: 2.5.1)
lwt.react           (version: 2.5.1)
lwt.simple-top      (version: 2.5.1)
lwt.ssl             (version: 2.5.1)
lwt.syntax          (version: 2.5.1)
lwt.syntax.log      (version: 2.5.1)
lwt.syntax.options  (version: 2.5.1)
lwt.unix            (version: 2.5.1)
nocrypto.lwt        (version: 0.5.1)
pvem_lwt_unix       (version: 0.0.1)
tls                 (version: 0.7.0)
tls.lwt             (version: 0.7.0)

rgrinberg added a commit to rgrinberg/ocaml-conduit that referenced this issue Dec 12, 2015
Server in `Conduit_lwt_tls` waits for a user callback to finish before
accepting more connections. Instead, it should only wait until the
connection is accepted and detach the client callback

Fix mirage#97
rgrinberg added a commit to rgrinberg/ocaml-conduit that referenced this issue Dec 12, 2015
Server in `Conduit_lwt_tls` waits for a user callback to finish before
accepting more connections. Instead, it should only wait until the
connection is accepted and detach the client callback

Fix mirage#97
@rgrinberg
Copy link
Member

@smondet I appreciate your persistence on this issue, could you please test if #101 fixes your problem?

@smondet
Copy link
Contributor Author

smondet commented Dec 13, 2015

@rgrinberg It works (I did opam pin add -k git conduit "https://github.com/rgrinberg/ocaml-conduit#fix97" ). Thanks !

rgrinberg added a commit to rgrinberg/ocaml-conduit that referenced this issue Dec 21, 2015
Server in `Conduit_lwt_tls` waits for a user callback to finish before
accepting more connections. Instead, it should only wait until the
connection is accepted and detach the client callback

Fix mirage#97
@avsm avsm mentioned this issue Dec 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants