-
Notifications
You must be signed in to change notification settings - Fork 18
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
async: add close_finished #73
base: master
Are you sure you want to change the base?
Conversation
@anmonteiro ping? |
haven't had a chance to review this yet. It's going to be a few more days. |
reader_thread () ) | ||
| `Yield -> Runtime.yield_reader t reader_thread | ||
| `Close -> | ||
(* Needed ?*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this might not be needed but right now it doesn't hurt to have. I'm guessing if a program is running this branch, read_complete
will always have been filled. Could be worth it to assert that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this async code is notoriously hard to follow, I don't recall very much now. All I know is this code works in prod. Agree for asserting things that we suppose true! :)
@@ -82,4 +82,5 @@ module type Client = sig | |||
val upgrade : _ t -> Gluten.impl -> unit | |||
val shutdown : _ t -> unit Deferred.t | |||
val is_closed : _ t -> bool | |||
val close_finished : _ t -> unit Deferred.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of introducing a new API, could we make this part of the val shutdown: _ t -> unit Deferred.t
process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be used as a functor for Persistent_connection_kernel.Make
, it should follow this interface:
module type Closable = sig
(** a connection type *)
type t
(** [close t] closes the connection. The returned deferred becomes determined once any
resources needed to maintain the connection have been released. *)
val close : t -> unit Deferred.t
(** [is_closed t] returns true if [close] has ever been called (even if the returned
deferred has not yet been fulfilled).
Note that some modules implementing [Closable] may call close internally upon
noticing that the connection was closed by the other side. The interface of such a
module ought to say that this is the case. *)
val is_closed : t -> bool
(** [close_finished t] becomes determined at the same time as the result of the first
call to [close]. [close_finished] differs from [close] in that it does not have the
side effect of initiating a close. *)
val close_finished : t -> unit Deferred.t
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, since there is a parameter it cannot be used directly as an argument to Persistent_connection_kernel.Make
. I used this patch in an internal fork to ocaml-h2
that I could maybe upstream at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But as the doc says, close
and close_finished
have not the same semantics.
Also, would not be better to call shutdown
-> close
since the socket is closed in the process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- leaving this here for my future reference: https://github.com/janestreet/async_kernel/blob/9f747452c88fe716cda4bd6f29ef0f3cb1ff3a39/persistent_connection_kernel/src/persistent_connection_kernel_intf.ml#L15
would not be better to call shutdown -> close since the socket is closed in the process?
works for me, would you like to propose a separate PR for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you allow me to push to your branch (here are some instructions)?
I have a few cosmetic fixes I'd like to push.
I could not find how to give you access to the PR, gave you write access to the repo instead. |
I needed this to be able to detect connection cutoff in order to use
Persistent_connection_kernel.Make
and have persistent connections.I ran into an issue while interacting with a gRPC service in a long polling fashion.