{"action":"created","issue":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/210","labels_url":"https://api.github.com/repos/ocaml/ocaml/issues/210/labels{/name}","comments_url":"https://api.github.com/repos/ocaml/ocaml/issues/210/comments","events_url":"https://api.github.com/repos/ocaml/ocaml/issues/210/events","html_url":"https://github.com/ocaml/ocaml/pull/210","id":92029869,"number":210,"title":"Warning to report fd leaks (channels that die without being closed)","user":{"login":"alainfrisch","id":3305274,"avatar_url":"https://avatars.githubusercontent.com/u/3305274?v=3","gravatar_id":"","url":"https://api.github.com/users/alainfrisch","html_url":"https://github.com/alainfrisch","followers_url":"https://api.github.com/users/alainfrisch/followers","following_url":"https://api.github.com/users/alainfrisch/following{/other_user}","gists_url":"https://api.github.com/users/alainfrisch/gists{/gist_id}","starred_url":"https://api.github.com/users/alainfrisch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alainfrisch/subscriptions","organizations_url":"https://api.github.com/users/alainfrisch/orgs","repos_url":"https://api.github.com/users/alainfrisch/repos","events_url":"https://api.github.com/users/alainfrisch/events{/privacy}","received_events_url":"https://api.github.com/users/alainfrisch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-06-30T08:55:18Z","updated_at":"2015-11-24T11:39:03Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ocaml/ocaml/pulls/210","html_url":"https://github.com/ocaml/ocaml/pull/210","diff_url":"https://github.com/ocaml/ocaml/pull/210.diff","patch_url":"https://github.com/ocaml/ocaml/pull/210.patch"},"body":"This implements what has been discussed on http://caml.inria.fr/mantis/view.php?id=6902 , namely a text on stderr to report in/out channels that are finalized without being closed.\r\n\r\nOnly channels created by functions in Pervasives are currently subject to the check (not those obtained from Unix functions, where the \"ownership\" of the underlying fd is not explicit).\r\n\r\nThe warning mentions the path passed to the `open_in/open_out` function (which can be a local path, perhaps not even referring to an existing file any more, btw).  A primitive exists to set the name of channels, but it is currently not directly exposed to the user (only used implicitly by `open_*` functions).\r\n\r\nThere is no attempt to report a warning on program termination (if the channel is not collected).  There is already some logic to flush all remaining channels automatically when program exits. Perhaps this should be revisited, since this can easily hide non-closed channels for short-living tests (if the program terminates before the channel value is finalized) and make the semantics depend on the Gc.  I'd be in favor of a more radical approach: simply report the same warning at exit time for all remaining non-closed channels, but this needs to be further discussed.\r\n\r\nWarnings are enabled by default but can be disabled by a new function in Pervasives.  I can imagine more such runtime warnings to be introduced later, so the name of that function is quite general.\r\n\r\nIt was also proposed to allow controlling warnings through OCAMLRUNPARAM, but this is currently not implemented."},"comment":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/comments/159239699","html_url":"https://github.com/ocaml/ocaml/pull/210#issuecomment-159239699","issue_url":"https://api.github.com/repos/ocaml/ocaml/issues/210","id":159239699,"user":{"login":"damiendoligez","id":19104,"avatar_url":"https://avatars.githubusercontent.com/u/19104?v=3","gravatar_id":"","url":"https://api.github.com/users/damiendoligez","html_url":"https://github.com/damiendoligez","followers_url":"https://api.github.com/users/damiendoligez/followers","following_url":"https://api.github.com/users/damiendoligez/following{/other_user}","gists_url":"https://api.github.com/users/damiendoligez/gists{/gist_id}","starred_url":"https://api.github.com/users/damiendoligez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiendoligez/subscriptions","organizations_url":"https://api.github.com/users/damiendoligez/orgs","repos_url":"https://api.github.com/users/damiendoligez/repos","events_url":"https://api.github.com/users/damiendoligez/events{/privacy}","received_events_url":"https://api.github.com/users/damiendoligez/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T11:39:03Z","updated_at":"2015-11-24T11:39:03Z","body":"> I suspect it makes sense to warn even more seriously when an error is raised\r\n\r\nThen we should also warn in the `atexit` function when flushing results in an error.\r\n"}}