Skip to content

Commit a365c6d

Browse files
committed
upgrade: fix async runtime
The deferred returned by the ugprade handler will dicatate when the fd will be closed.
1 parent 2c86e47 commit a365c6d

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

async/httpaf_async.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,10 @@ module Server = struct
9494
type 'a t =
9595
| Ignore
9696
| Raise
97-
| Handle of (([`Active], 'a) Socket.t -> Httpaf.Request.t -> Httpaf.Response.t -> unit)
97+
| Handle of (([`Active], 'a) Socket.t -> Httpaf.Request.t -> Httpaf.Response.t -> unit Deferred.t)
9898

9999
let to_handler = function
100-
| Ignore -> (fun socket _request _response ->
101-
don't_wait_for (Fd.close (Socket.fd socket)))
100+
| Ignore -> (fun socket _request _response -> Fd.close (Socket.fd socket))
102101
| Raise ->
103102
(fun socket _request _response ->
104103
don't_wait_for (Fd.close (Socket.fd socket));
@@ -160,7 +159,7 @@ module Server = struct
160159
(* Log.Global.printf "write_yield(%d)%!" (Fd.to_int_exn fd); *)
161160
Server_connection.yield_writer conn writer_thread;
162161
| `Upgrade(request, response) ->
163-
upgrade_handler socket request response
162+
upgrade_handler socket request response >>> Ivar.fill write_complete
164163
| `Close _ ->
165164
(* Log.Global.printf "write_close(%d)%!" (Fd.to_int_exn fd); *)
166165
Ivar.fill write_complete ();

async/httpaf_async.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Server : sig
66
type 'a t =
77
| Ignore
88
| Raise
9-
| Handle of (([`Active], 'a) Socket.t -> Request.t -> Response.t -> unit)
9+
| Handle of (([`Active], 'a) Socket.t -> Request.t -> Response.t -> unit Deferred.t)
1010
end
1111

1212
val create_connection_handler

0 commit comments

Comments
 (0)