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

Handle panic in the init closure/future of get_or_insert_with and get_or_try_insert_with #46

Merged
merged 8 commits into from
Sep 20, 2021

Conversation

tatsuya6502
Copy link
Member

@tatsuya6502 tatsuya6502 commented Sep 18, 2021

This PR addresses the issue reported by #43.

Changes

When the user-provided init future/closure for get_or_insert_with or get_or_try_insert_with method has panicked, it will catch the panic, remove the waiter for the key, and resume the panic. It also restarts other in-progress (actually blocked) method calls on the same key.

  • Add futures crate for Moka's future feature.
  • Update future::Cache to handle panic in the init future of get_or_insert_with and get_or_try_insert_with.
  • Update sync::Cache to handle panic in the init future of get_or_insert_with and get_or_try_insert_with.
  • Add unit tests.

Fixes #43

- Update `future::Cache` to handle panic in the `init` future of
  `get_or_insert_with` and `get_or_try_insert_with`.
- Add `futures` crate as optional for `future` feature.
@tatsuya6502 tatsuya6502 self-assigned this Sep 18, 2021
@tatsuya6502 tatsuya6502 added this to the v0.6.0 milestone Sep 18, 2021
Add sync and time features to Tokio in the dev-dependency.
@tatsuya6502 tatsuya6502 added the bug Something isn't working label Sep 18, 2021
Tweak the code from previous commits under `future` module.
Update `sync::Cache` to handle panic in the `init` closure of
`get_or_insert_with` and `get_or_try_insert_with`.
@tatsuya6502 tatsuya6502 marked this pull request as ready for review September 18, 2021 09:17
Copy link
Member Author

@tatsuya6502 tatsuya6502 left a comment

Choose a reason for hiding this comment

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

Merging.

@tatsuya6502 tatsuya6502 merged commit 5a35152 into master Sep 20, 2021
@tatsuya6502 tatsuya6502 deleted the handle-user-fn-panics branch September 20, 2021 00:17
@nickguletskii
Copy link

nickguletskii commented Sep 20, 2021

Thank you for fixing this quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic causes "thread panicked at 'internal error: entered unreachable code'"
2 participants