-
-
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
Feature Proposal: Task Dumps #5457
Comments
This is very exciting! I'd personally find a Display implementation that forks a child, pauses threads, etc to be pretty strange. I thought the code example at the top of the issue just had a typo until I got down to the appendix! Having a It may be worth considering whether the ptrace side of things should be in scope, at least initially - the dump process could e.g. alternatively wait for a bit for well-behaved running tasks to yield and users could rely on a standard thread dumper (e.g. rstack-self or minidumper) to handle thread dumps of blocking code or badly behaved tasks. |
This is the route I originally took, but I encountered some challenges that lead me to the A task dump is meant to be an atomic snapshot of runtime state. In the If the snapshot is taken at the invocation of
Both of these choices are expensive, and the first potentially introduces a deadlock hazard, too. Alternatively, the snapshot could be taken when These various complications lead me to consider if I could just fuse the snapshot and serialization steps together, hence my proposal for a |
I would expect that calling I don't see why a task dump would inherently need to hold locks or store runtime internals - it could be as simple as just storing the JSON directly in a string or whatever for the MVP. A display implementation is supposed to be the canonical textual representation of the type. It seems very strange to me that the canonical textual representation of a Handle is a JSON-formatted dump of the tasks running on the handle's associated runtime. |
I think that it's worth stepping back and considering the possible uses of this information and how much dependency they have on the functionality that must be in tokio. Providing an already serialized JSON string, assumes that the primary use for dumping the state of a runtime is outside of that application. This makes it more work for an application to introspect the state of its own runtime and act upon it (because the state would have to be deserialized again to be reusable). Additionally, this requires adding significant dependencies to tokio in order to support ( If instead, tokio were to provide its state as an object, that information could be used within the same application, and could also (albeit with more boilerplate) be serialized into a format suitable for export (e.g. JSON). This option has the advantage that it doesn't introduce additional dependencies. I don't want to argue that adding new dependencies is a no go, especially when behind some feature flag, but I believe that if we consider the trade-offs, a first approach which provides an API that gives access to the important information (runtime snapshot state) in a more flexible manner and introducing fewer dependencies would be advisable. Additions (such as providing a serialized state) could then be considered on top of that API. Regarding the concern that some |
Here are my initial thoughts on this: Task Iteration: sounds reasonable. |
Major Changes:
In Java, thread dumps are an invaluable tool for debugging a stuck application in production. When a user requests a thread dump from a JVM, they receive text including the following information about each thread managed by the JVM:
RUNNABLE
,WAITING
, orBLOCKED
.This information is useful for debugging deadlocks.
Thread dumps provide a starting point for debugging deadlocks. A programmer can thread dump a deadlocked program, identify the
BLOCKED
threads, and inspect their call stacks to identify the resources they are blocked on.I propose bringing an analogue to Tokio: "task dumps". A task dump is a comprehensive snapshot of the state of a Tokio application. This proposal will allow tokio services to briefly pause their work, reflect upon their internal runtime state, and comprehensively report that state to their operator.
Guide-Level Explanation
The task dump API is gated behind
--cfg tokio_unstable --cfg tokio_taskdump
. A task dump is captured by invokingHandle::capture
. For example, executing this program:Will produce an output like:
Progress
See #5638
Related Reading
This document contrasts several potential approaches to tracing future state.
The text was updated successfully, but these errors were encountered: