Skip to content

More robust file implementation #157

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

Merged
merged 2 commits into from Sep 8, 2019
Merged

More robust file implementation #157

merged 2 commits into from Sep 8, 2019

Conversation

ghost
Copy link

@ghost ghost commented Sep 7, 2019

This is a reimplementation of the Files state machine.

The previous implementation was simple and a bit naive. It was not fundamentally wrong but had surprises in some corner cases. For example, if an async read operation was started but we timed out on it, the file cursor would move even though we didn't complete the operation. The new implementation will move the cursor only when read/write operations complete successfully.

There was also a deadlock hazard in the case where multiple tasks were concurrently reading or writing to the same file, in which case some task wakeups would be lost. This PR fixes the problem.

A nice consequence of this PR: futures-channel is now unused, so we can remove it from the dependency list.

Copy link
Contributor

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems significantly better than what we had before. Much easier to follow, and the removal of futures-preview-channel is a nice bonus!

@yoshuawuyts
Copy link
Contributor

Rebased on master to enable tests to pass.

bors bot added a commit that referenced this pull request Sep 8, 2019
157: More robust file implementation r=stjepang a=stjepang

This is a reimplementation of the `File`s state machine.

The previous implementation was simple and a bit naive. It was not fundamentally wrong but had surprises in some corner cases. For example, if an async read operation was started but we timed out on it, the file cursor would move even though we didn't complete the operation. The new implementation will move the cursor only when read/write operations complete successfully.

There was also a deadlock hazard in the case where multiple tasks were concurrently reading or writing to the same file, in which case some task wakeups would be lost. This PR fixes the problem.

A nice consequence of this PR: `futures-channel` is now unused, so we can remove it from the dependency list.

Co-authored-by: Stjepan Glavina <[email protected]>
@ghost ghost deleted a comment from bors bot Sep 8, 2019
@ghost
Copy link
Author

ghost commented Sep 8, 2019

bors r+

bors bot added a commit that referenced this pull request Sep 8, 2019
157: More robust file implementation r=stjepang a=stjepang

This is a reimplementation of the `File`s state machine.

The previous implementation was simple and a bit naive. It was not fundamentally wrong but had surprises in some corner cases. For example, if an async read operation was started but we timed out on it, the file cursor would move even though we didn't complete the operation. The new implementation will move the cursor only when read/write operations complete successfully.

There was also a deadlock hazard in the case where multiple tasks were concurrently reading or writing to the same file, in which case some task wakeups would be lost. This PR fixes the problem.

A nice consequence of this PR: `futures-channel` is now unused, so we can remove it from the dependency list.

Co-authored-by: Stjepan Glavina <[email protected]>
@bors
Copy link
Contributor

bors bot commented Sep 8, 2019

Build succeeded

  • continuous-integration/travis-ci/push

@bors bors bot merged commit 6ed0e85 into async-rs:master Sep 8, 2019
@ghost ghost deleted the simplify-file branch September 8, 2019 09:54
@CoolOppo
Copy link

CoolOppo commented Jan 9, 2020

I was trying to get an understanding of how reading a file asynchronously worked in async-std so I perused the source. I'm very new to async. While carefully walking through all the scenarios with the Lock and LockGuard implementations I was blown away by how great this code is. I wanted to stop by and leave a thank you. This is a great example on how to handle locking and unlocking and waking up. Major kudos to everyone involved.

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

Successfully merging this pull request may close these issues.

2 participants