-
Notifications
You must be signed in to change notification settings - Fork 176
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
Proposals to get rid of the obscure Lwt_io.Channel_closed("input") exception when a Lwt_process times-out #919
Comments
I think a lighter proposal is to create a first thought: NodeJs API style but don't know how to typeIn case we give:Lwt_main.run (Lwt_process.with_process_in ~timeout:(`Ignore 1.) ("", [|"sleep"; "2"|]) (fun proc -> Lwt_io.read proc#stdout)) What will be in module Lwt = struct
type 'a t = 'a ref
end
type process_in = int
type ('handler, 'return) onTimeout =
| Catch: float -> (process_in -> exn -> 'return Lwt.t, 'return) onTimeout
| Fail: float -> (process_in -> 'return Lwt.t, 'return) onTimeout
| NoTimeout: (process_in -> 'return Lwt.t, 'return) onTimeout (* for the default value *)
let with_process_in: type return. ?timeout:('handler, return) onTimeout -> 'handler -> return Lwt.t = fun ?(timeout=NoTimeout) f ->
match timeout with
NoTimeout -> f 4
| Fail _t -> f 3 (Invalid_argument "timeout")
| Catch _ -> f 3 |
I'm not sure all the functions in this module should return promises which are rejected by an exception. I think it might be interesting for users to still recover the status of the killed process. So here are some alternatives:
It's a bit annoying to change the API for the users who don't set a |
See printf it use the first argument a GADT to encode the rest of argument https://github.com/ocaml/ocaml/blob/1546e1f86f87485637719c86d92f32df9292997f/stdlib/camlinternalFormatBasics.ml#L525 I think keeping optional will we the hard part if possible. |
I managed to get their https://gist.github.com/Et7f3/3b4f09ddf5ac1eacf0f4a360d8154d32 this mean we either need to make non optional or force in case of NoTimeout to return |
That gets us half of the way there… but it still breaks backwards compatibility. Another possible approach is to deprecate the use of |
I haven’t tried yet but I like this approach very much. I don’t think deprecating a parameter is allowed in the OCaml syntax (at least not automatically using I am very much in favour of that solution. |
We might break a few packages by making this breaking change, but we should be able to propose patches to either use |
currently (lwt 5.5.0) raises
Worse,
Does not fail at all.
I think it would be less confusing to have the functions from
Lwt_process
which takes~timeout
fail with a newLwt_process.Timeout
exception.If you prefer not to change the behaviour, maybe either add a new
?fail_on_timeout:bool
argument, or changing the type of?timeout
fromfloat
to something like[`Ignore of float | `Fail of float]
would be enough.EDIT: Personally I would prefer the second proposal as it would make users aware of the issue/choice in a more systematic manner.
I just spent days trying to debug why my code would fail with an obscure lwt exception all of a sudden and I wish for no-one to go through that pain ever again.
The text was updated successfully, but these errors were encountered: