You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"at_exit" function run twice with cleanup-at-exit runtime option #7796
Original bug ID: 7796 Reporter:@xavierleroy Assigned to:@xavierleroy Status: resolved (set by @xavierleroy on 2018-05-23T17:51:00Z) Resolution: fixed Priority: normal Severity: major Platform: x86-64 OS: Ubuntu Linux 16.04 Version: 4.07.0+dev/beta2/rc1/rc2 Target version: 4.07.0+dev/beta2/rc1/rc2 Fixed in version: 4.07.0+dev/beta2/rc1/rc2 Category: runtime system and C interface Related to:#7178#7253 Monitored by:@nojb@gasche@dbuenzli
Bug description
When "c=1" is put in OCAMLRUNPARAM, text printed to standard output in an at_exit function ends up written twice to standard output.
I agree that caml_shutdown should run the at-exit functions. This is especially true if the OCaml code is embedded as a library in a larger program. I also think that we should not run the at-exit functions twice, and will propose a GPR for that.
Activity
vicuna commentedon May 17, 2018
Comment author: @xavierleroy
It seems that all "at_exit" functions are run TWICE if cleanup-at-exit is set. This is a serious mistake.
vicuna commentedon May 17, 2018
Comment author: @nojb
at_exit functions are called from caml_shutdown
https://github.com/ocaml/ocaml/blob/trunk/byterun/startup_aux.c#L159
(caml_shutdown is called if cleanup_on_exit is set), but if the program finished normally, they would also have been called via std_exit.
vicuna commentedon May 17, 2018
Comment author: @nojb
The change to call at_exit functions from caml_shutdown was thread-related:
commit a6cad36
Author: Max Mouratov mmouratov@gmail.com
Date: Sun Nov 29 23:26:18 2015 +0500
vicuna commentedon May 17, 2018
Comment author: @xavierleroy
I agree that caml_shutdown should run the at-exit functions. This is especially true if the OCaml code is embedded as a library in a larger program. I also think that we should not run the at-exit functions twice, and will propose a GPR for that.
vicuna commentedon May 17, 2018
Comment author: @dbuenzli
Since people might look into the whole machinery I just want to relate this to #7253 and #7178 and associated aborted GPR.
vicuna commentedon May 17, 2018
Comment author: @xavierleroy
Proposed fix at #1783 .
It does not address the other issues mentioned by @dbuenzli, but it an improvement nonetheless.
vicuna commentedon May 21, 2018
Comment author: @xavierleroy
Alternate, improved fix at #1790
It also addresses #7253.
vicuna commentedon May 23, 2018
Comment author: @xavierleroy
Merged #1790