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

async: add close_finished #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

vbmithr
Copy link

@vbmithr vbmithr commented Dec 9, 2023

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.

@vbmithr
Copy link
Author

vbmithr commented Dec 19, 2023

@anmonteiro ping?

@anmonteiro
Copy link
Owner

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 ?*)
Copy link
Owner

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.

Copy link
Author

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
Copy link
Owner

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?

Copy link
Author

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

Copy link
Author

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.

Copy link
Author

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Owner

@anmonteiro anmonteiro left a 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.

@vbmithr
Copy link
Author

vbmithr commented Mar 15, 2024

I could not find how to give you access to the PR, gave you write access to the repo instead.

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

Successfully merging this pull request may close these issues.

2 participants