Skip to content
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

UnliftIO.IO.File: Expose withHandleFd, warn against handleToFd #64

Open
nh2 opened this issue Jul 24, 2020 · 2 comments
Open

UnliftIO.IO.File: Expose withHandleFd, warn against handleToFd #64

nh2 opened this issue Jul 24, 2020 · 2 comments

Comments

@nh2
Copy link
Member

nh2 commented Jul 24, 2020

We should expose our withHandleFd function somewhere because when you want to do something like fchmod() (which needs an Fd) on the Handle, the most luring solution is System.Posix.IO's handleToFd, which is brutally wrong because

This function has the side effect of closing the Handle

If you use handleToFd (which I just did on my server, oops), it will just mark the Handle as closed (but keep the underlying Fd open), so then the hClose that unliftio does will be silently ignored, and the Fd will be leaked until the server crashes (and so did mine).

So I think we should make our better withHandleFd publicly available, and write somewhere in the module that this is what should be used if you need low-level FD access from withBinaryFile*.


cc @lehins

@nh2
Copy link
Member Author

nh2 commented Jul 24, 2020

I made handleToFd commentary more explicit in haskell/unix#155.

@lehins
Copy link
Contributor

lehins commented Jul 24, 2020

@nh2 I remember when you where reviewing my PR about this functionality you wanted to make it more general. I do like that idea, but I do not agree that such API should provided by unliftio. The purpose of this package is to provide OS agnostic UX, which means exporting functions that operate on unix Fds will be sending the wrong message the user. What I would recommend is that someone extracts the posix file operations provided in this package and re-designs them to be generic enough to be reusable in other areas and situations, withHandleFd is a great example of such function. Once such package is available then unliftio can use it instead of defining specialized functions for handling atomic file operations the way it does now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants