Skip to content

Commit

Permalink
Merge pull request #458 from djs55/mux-close-shutdown
Browse files Browse the repository at this point in the history
mux: ocaml: avoid sending Shutdown after Close
  • Loading branch information
djs55 authored Feb 5, 2019
2 parents 1ddfecc + 4bb313b commit 218f014
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- checkout
- run: brew uninstall python # remove files in /usr/local/bin
- run: brew install wget pkg-config dylibbundler
- run: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/72ce8812eaa33abe23533dfa021b51351a6b9c3e/Formula/opam.rb
- run: brew install https://gist.githubusercontent.com/djs55/7a94ee5aeb882ef5399c0485d2affdda/raw/bc04ff96e0082d7ee07642337dbb77c51b93d678/opam.rb
- run: make
- run: make artefacts
- run: make test
Expand Down
11 changes: 8 additions & 3 deletions src/forwarder/multiplexer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,14 @@ module Make (Flow : Mirage_flow_lwt.S) = struct
Lwt.return (Ok ())

let shutdown_write channel =
channel.subflow.Subflow.shutdown_sent <- true;
send channel.outer Frame.{command= Shutdown; id= channel.id} ;
flush channel.outer
(* Avoid sending Shutdown twice or sending a shutdown after a Close *)
if is_write_eof channel
then Lwt.return_unit
else begin
channel.subflow.Subflow.shutdown_sent <- true;
send channel.outer Frame.{command= Shutdown; id= channel.id} ;
flush channel.outer
end

let close channel =
(* Don't send Close more than once *)
Expand Down
31 changes: 31 additions & 0 deletions src/hostnet_test/test_forward_protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,34 @@ let test_close_close () =
Lwt.return_unit
)

let test_close_shutdown () =
Host.Main.run
(let left_flow = Shared_memory.create () in
let right_flow = Shared_memory.otherend left_flow in
let left_mux =
Mux.connect left_flow "left" (fun _channel _destination ->
Lwt.fail_with "left side shouldn't get a connection" )
in
let right_mux =
Mux.connect right_flow "right" (fun channel destination ->
Log.debug (fun f ->
f "Got a connection to %s" (Destination.to_string destination)
) ;
Mux.Channel.close channel )
in
Mux.Channel.connect left_mux (`Tcp (Ipaddr.V4 Ipaddr.V4.localhost, 8080))
>>= fun channel ->
Mux.Channel.close channel
>>= fun () ->
Mux.Channel.shutdown_write channel
>>= fun () ->
if not (Mux.is_running left_mux)
then failwith "left_mux has failed";
if not (Mux.is_running right_mux)
then failwith "right_mux has failed";
Lwt.return_unit
)

let send channel n =
let sha = Sha256.init () in
let rec loop n =
Expand Down Expand Up @@ -370,6 +398,9 @@ let mux_suite =
; ( "check that double-close doesn't break the connection"
, `Quick
, test_close_close )
; ( "check that shutdown after close doesn't break the connection"
, `Quick
, test_close_shutdown )
; ( "check that the multiplexer can handle concurrent connections"
, `Quick
, stress_multiplexer ) ] ) ]
Expand Down

0 comments on commit 218f014

Please sign in to comment.