-
Notifications
You must be signed in to change notification settings - Fork 73
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
Eio.Path.load causes "file descriptor used after calling close!" error #740
Comments
The path argument to |
@talex5 Thanks, that is extremely helpful, I did not realise that the path itself is an ephemeral resource; I had wrongly assumed it was just pure data that can be used whenever (e.g. to acquire an actual resource, like a flow). I think that your guess is correct, as in my code I have one routine that scans a directory to get a bunch of paths to work with, and then another routine that does something with the accumulated paths. Naturally, the directory resource is closed before the second routine runs. Do you have any recommendations about how to restructure this code to work properly with Eio's model? |
Note: Assuming you do want that, you can either pass a switch to the scanning routine, so that the opened directories remain open after it returns, or you could delay calling |
Oh! That's really helpful, thanks! For some reason I thought I needed to call |
@jonsterling @talex5 Could it then be that the usage of this function is causing some issues? https://git.sr.ht/~jonsterling/ocaml-forester/tree/main/item/bin/forester/main.ml#L8 On windows, I am hitting a https://git.sr.ht/~jonsterling/ocaml-forester/tree/main/item/bin/forester/main.ml#L48 In my work then, instead of I have let parse_file fp =
let content = Eio.Path.load fp in
parse_string content which results in the above error. |
Apparently this is creating some kind of sandbox that confines the resulting paths, and binds them to the lifetime of the directory resource. see ocaml-multicore/eio#740
@kentookura I'm adding an example of reading files to examples/fs in #745. That's working on Windows in CI; does it work for you? |
Yes, the example works, thanks. |
I was experimenting with some of my code to test the performance impact of reading some text from a channel, vs. using
Eio.Path.load
, and I noticed something very strange. When I changed my code to useEio.Path.load
, I consistently get the following exception:Now, it strikes me that this exception should not be possible if all I am doing is calling
load
, which should surely be managing its own resources. Is this expectation correct, or is there a reason why this might be happening?EDIT: I notice this also happens when I use
with_open_in
, which I guess makes sense becauseload
is a wrapper of this. But I am puzzled about how it could be happening nonetheless.The text was updated successfully, but these errors were encountered: