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

can there be a race between a read or write operation and a close #782

Closed
FrankReh opened this issue Feb 7, 2023 · 3 comments
Closed

can there be a race between a read or write operation and a close #782

FrankReh opened this issue Feb 7, 2023 · 3 comments

Comments

@FrankReh
Copy link
Contributor

FrankReh commented Feb 7, 2023

If a read or write operation is in-flight, has it incremented an entry in the file descriptor table?, so if a close for the same file descriptor were to come to the same submission queue, or a different one, or as a synchronous close(2) call, will the file descriptor be kept open until the in-flight read or write is done?

@FrankReh
Copy link
Contributor Author

FrankReh commented Feb 7, 2023

I understand the risk of a race if the sqe had not been flushed to the device yet and a close for the same file descriptor made it to the kernel first though another mechanism. I'm curious whether once the enter call has returned so the submission queue has a been fully read, is it safe to allow a close for a related file descriptor to happen, on the same thread, or is it necessary to hold the close until the operation has completed?

@isilence
Copy link
Collaborator

isilence commented Feb 7, 2023

io_uring resolves files (and takes refs) lazily, so you'd need to wait for completions or order close requests with reads/etc. (e.g. via links). In practice, files are eagerly resolved except for links and draining but that may change.

@FrankReh
Copy link
Contributor Author

FrankReh commented Feb 7, 2023

Ok. I don't like the answer, (lazy references are taken), but I'm very happy you could answer this so quickly. It means the code that's been in tokio-uring to block closing until all operations on the fd are complete is justified and I won't be lobbying to remove it.

Thank you!

Edit: Rather than say I didn't like the answer, I should have said I understand but was hoping for a different answer. Your uring device is awesome and we're lucky to have it.

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