From b6bd33af688892d0905b1ea351dcf49ae6af2b6a Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Tue, 21 Jan 2020 22:35:52 -0800 Subject: [PATCH] server_connection: fix regression which caused `wakeup_writer` bookkeeping to be wrong for async responses (#37) Introduced in https://github.com/inhabitedtype/httpaf/pull/161 --- CHANGES.md | 5 +++++ lib_test/test_server_connection.ml | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ba32903..807f73d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -55,6 +55,11 @@ Unreleased [inhabitedtype/httpaf#162](https://github.com/inhabitedtype/httpaf/issues/162) - httpaf-async: Add HTTPS support for the Async bindings ([#35](https://github.com/anmonteiro/httpaf/pull/35)). +- httpaf: Fix upstream regression introduced in + [inhabitedtype/httpaf#161](https://github.com/inhabitedtype/httpaf/pull/161) + that caused `wake_up_writer` callback bookkeeping to be slightly wrong due to + physical equality, producing runtime errors in cases where it shouldn't + ([#37](https://github.com/anmonteiro/httpaf/pull/37)). httpaf (upstream) 0.6.5 -------------- diff --git a/lib_test/test_server_connection.ml b/lib_test/test_server_connection.ml index e724d66..a61ec3a 100644 --- a/lib_test/test_server_connection.ml +++ b/lib_test/test_server_connection.ml @@ -723,6 +723,28 @@ let test_empty_body_no_immediate_flush () = true !reader_woken_up; ;; +let test_yield_before_starting_a_response () = + let reader_woken_up = ref false in + let response = Response.create `OK in + let continue_response = ref (fun () -> ()) in + let request_handler reqd = + continue_response := (fun () -> + let resp_body = Reqd.respond_with_streaming reqd response in + Body.close_writer resp_body) + in + let t = create ~error_handler request_handler in + reader_ready t; + writer_yielded t; + read_request t (Request.create `GET "/"); + yield_reader t (fun () -> reader_woken_up := true); + yield_writer t ignore; + !continue_response (); + write_response t ~body:"" response; + writer_yielded t; + Alcotest.(check bool) "Reader woken up" + true !reader_woken_up; +;; + let tests = [ "initial reader state" , `Quick, test_initial_reader_state ; "shutdown reader closed", `Quick, test_reader_is_closed_after_eof @@ -750,4 +772,5 @@ let tests = ; "malformed request, streaming response", `Quick, test_malformed_request_streaming_error_response ; "`flush_headers_immediately` with empty body", `Quick, test_immediate_flush_empty_body ; "empty body with no immediate flush", `Quick, test_empty_body_no_immediate_flush + ; "yield before starting a response", `Quick, test_yield_before_starting_a_response ]