Repository navigation
Update format.ml to avoid Queue.empty - #13572
Conversation
prefer take_opt to exception handling
typo
Extra space
|
I would find the code easier to explain if we did not print the token if we realize that the queue has become empty, something like: In any case, I think there should be a comment that explains the choice to deal with concurrent races in best effort. |
|
Note: I am not, a priori, convinced that we should try to slightly better support this use-case, instead of failing loudly with an exception (as we were doing). Why would you try to rely on this, instead of fixing your code to avoid racing on format buffers? |
|
Hello Gabriel,
The problem I had, is when you fall into the race condition while adding
debugging message to solve a problem and get an uncaught exception, you
may loose a lot of time. Undefined behavior and bad printing would have
be OK in this case, but instead I got a nightmarish debugging session!
I think uncaught exception is really bad in a printing function, that
can be a log inside an exception handler.
Gabriel Scherer ***@***.***> writes:
… I would find the code easier to explain if we did not print the token if we realize that the queue has become empty, something like:
match take_opt pp_queue with
| None -> ()
| Some ->
(* printing logic *)
In any case, I think there should be a comment that explains the choice to deal with concurrent races in best effort.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
--
Christophe Raffalli
web: https://raffalli.eu
|
Done. Thanks for your comment. |
|
Following the line of thoughts around "fail loudly if there is an issue": would failing with an |
As was established in this PR there's no need for the "concurrent" but other than that I would much prefer if the stdlib fails loudly on race conditions rather than hiding them. |
|
Hello
Invalid_argument why not, but this is not really an invalid argument. A dedicated exception could be better than invalid_argument? Assert could be good to pointing to the code in format?
Le 27 octobre 2024 22:40:13 GMT-10:00, Gabriel Scherer ***@***.***> a écrit :
…Following the line of thoughts around "fail loudly if there is an issue": would failing with an `Invalid_argument` exception be okay, or are you saying that your code is catching all exceptions (including those that should not be recovered from) and that also would not work? If that would have worked for you, I think that `invalid_arg "Format: unsychronized concurrent access"` would have my preference over `()` in this case.
--
Reply to this email directly or view it on GitHub:
#13572 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
I think it's ok: you are giving an unsynchronized formatter to a formatting function. That's an invalid argument as per
I don't really care where the offending code is in |
Use invalid_arg
Update documentation.
|
I updated the code to use invalid_arg and updated also the documentation to document this exception. |
|
I am wondering if we could make it systematic that this exception is raised in case of thread unsafe use of the library? |
|
My understanding is that (Not completely fond of your error message but we are splitting hair. I'm sure @dbuenzli could make a good proposal and I would suggest to just reuse whatever he proposes.) |
|
perhaps something like: or if the |
I just did that, and updated my modification mentionning the exception in Format.mli. I still wounder if we can capture a few more case of unsynchronised use. Note: when I do logging in simple_httpd, I use one distinct file and formatter per domain. No mutex this way and |
gasche
left a comment
There was a problem hiding this comment.
This looks fine to me (see minor comments below). I'm not sure whether this qualifies as a "stdlib change that requires a second approval", but in case I'd ask @Octachron or @nojb or @OlivierNicole for a second opinion.
Octachron
left a comment
There was a problem hiding this comment.
Raising a clear exception for certain unsynchronized access sounds like a good to me too.
|
Merged (by squashing all commits), thanks! |
|
Thanks all for your comments! |
|
|
||
| ### Standard library: | ||
|
|
||
| - #13371: Avoid Queue.empty to be raised by Format when used concurrently. |
|
Gaëtan Gilbert ***@***.***> writes:
@SkySkimmer commented on this pull request.
-------------------------------------------------------------------------------------------------------------------------
In Changes:
> @@ -67,6 +67,10 @@ Working version
### Standard library:
+- #13371: Avoid Queue.empty to be raised by Format when used concurrently.
This is the number of the issue, not the number of the PR. I thought
this was OK too ?
… incorrect number
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
--
Christophe Raffalli
web: https://raffalli.eu
|
|
The convention is to cite all PRs and issues involved in the Changes entry (I will fix the Changes entry manually). |
Argh, no you are right, this is another issue with format. As this is merged, I do not know really what to do ? |
|
The typo are now fixed. |
|
Florian Angeletti ***@***.***> writes:
Thanks and sorry for that typo and the time it took to you.
Cheers, Christophe.
… The typo are now fixed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
--
Christophe Raffalli
web: https://raffalli.eu
|
issue #13463