-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
sync: add track_caller to public APIs #4808
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Functions that may panic can be annotated with `#[track_caller]` so that in the event of a panic, the function where the user called the panicking function is shown instead of the file and line within Tokio source. This change adds `#[track_caller]` to all the public APIs in the sync module of the tokio crate where the documentation describes how the function may panic due to incorrect context or inputs. In cases where `#[track_caller]` does not work, it has been left out. For example, it currently does not work on async functions, blocks, or closures. So any call stack that passes through one of these before reaching the actual panic is not able to show the calling site outside of tokio as the panic location. The following functions have call stacks that pass through closures: * `sync::watch::Sender::send_modify` * `sync::watch::Sender::send_if_modified` Additionally, in the above functions it is a panic inside the supplied closure which causes the function to panic, and so showing the location of the panic itself is desirable. The following functions are async: * `sync::mpsc::bounded::Sender::send_timeout` Tests are included to cover each potentially panicking function. Refs: tokio-rs#4413
Noah-Kennedy
approved these changes
Jul 5, 2022
Noah-Kennedy
approved these changes
Jul 5, 2022
wait what, double approve lol |
crapStone
pushed a commit
to Calciumdibromid/CaBr2
that referenced
this pull request
Jul 18, 2022
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dependencies | minor | `1.19.2` -> `1.20.0` | | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dev-dependencies | minor | `1.19.2` -> `1.20.0` | --- ### Release Notes <details> <summary>tokio-rs/tokio</summary> ### [`v1.20.0`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.20.0) [Compare Source](tokio-rs/tokio@tokio-1.19.2...tokio-1.20.0) ##### 1.20.0 (July 12, 2022) ##### Added - tokio: add track_caller to public APIs ([#​4772], [#​4791], [#​4793], [#​4806], [#​4808]) - sync: Add `has_changed` method to `watch::Ref` ([#​4758]) ##### Changed - time: remove `src/time/driver/wheel/stack.rs` ([#​4766]) - rt: clean up arguments passed to basic scheduler ([#​4767]) - net: be more specific about winapi features ([#​4764]) - tokio: use const initialized thread locals where possible ([#​4677]) - task: various small improvements to LocalKey ([#​4795]) ##### Fixed ##### Documented - fs: warn about performance pitfall ([#​4762]) - chore: fix spelling ([#​4769]) - sync: document spurious failures in oneshot ([#​4777]) - sync: add warning for watch in non-Send futures ([#​4741]) - chore: fix typo ([#​4798]) ##### Unstable - joinset: rename `join_one` to `join_next` ([#​4755]) - rt: unhandled panic config for current thread rt ([#​4770]) [#​4677]: tokio-rs/tokio#4677 [#​4741]: tokio-rs/tokio#4741 [#​4755]: tokio-rs/tokio#4755 [#​4758]: tokio-rs/tokio#4758 [#​4762]: tokio-rs/tokio#4762 [#​4764]: tokio-rs/tokio#4764 [#​4766]: tokio-rs/tokio#4766 [#​4767]: tokio-rs/tokio#4767 [#​4769]: tokio-rs/tokio#4769 [#​4770]: tokio-rs/tokio#4770 [#​4772]: tokio-rs/tokio#4772 [#​4777]: tokio-rs/tokio#4777 [#​4791]: tokio-rs/tokio#4791 [#​4793]: tokio-rs/tokio#4793 [#​4795]: tokio-rs/tokio#4795 [#​4798]: tokio-rs/tokio#4798 [#​4806]: tokio-rs/tokio#4806 [#​4808]: tokio-rs/tokio#4808 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xMTEuMSIsInVwZGF0ZWRJblZlciI6IjMyLjExMS4xIn0=--> Co-authored-by: cabr2-bot <[email protected]> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1458 Reviewed-by: crapStone <[email protected]> Co-authored-by: Calciumdibromid Bot <[email protected]> Co-committed-by: Calciumdibromid Bot <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When a user of tokio calls a function that panics when misused (e.g. calling
Mutex::blocking_lock()
from within a tokio runtime) then the user currentlysees the line number of the panic call inside tokio. It would be more informative
for the user to see the place where they called the panicking function.
It is still possible for the user to see the full stack trace by setting the
environment variable RUST_BACKLOG=1, so no useful information is
hidden.
This change is the 7th in a series towards closing #4413 (starting with #4772),
this change is for the sync functions in the main tokio crate.
Solution
Functions that may panic can be annotated with
#[track_caller]
so thatin the event of a panic, the function where the user called the
panicking function is shown instead of the file and line within Tokio
source.
This change adds
#[track_caller]
to all the public APIs in the syncmodule of the tokio crate where the documentation describes how the
function may panic due to incorrect context or inputs.
In cases where
#[track_caller]
does not work, it has been left out.For example, it currently does not work on async functions, blocks, or
closures. So any call stack that passes through one of these before
reaching the actual panic is not able to show the calling site outside
of tokio as the panic location.
The following functions have call stacks that pass through closures:
sync::watch::Sender::send_modify
sync::watch::Sender::send_if_modified
Additionally, in the above functions it is a panic inside the supplied
closure which causes the function to panic, and so showing the location
of the panic itself is desirable.
The following functions are async:
sync::mpsc::bounded::Sender::send_timeout
Tests are included to cover each potentially panicking function.
Refs: #4413