console icon indicating copy to clipboard operation
console copied to clipboard

warnings: indication that there are tasks on the runtime but the runtime itself is not running

Open nagisa opened this issue 2 years ago • 1 comments

In the past I have encountered an issue in an otherwise mostly synchronous codebase where I wanted to use opentelemetry exporter. I would write code as such (mostly from memory, does not necessarily compile):

let runtime = tokio::Runtime::builder().single_threaded().build();
let tracer = runtime.block_on(async { 
    opentelemetry_otlp::new_pipeline().install_simple(opentelemetry::runtime::Tokio);
});
// register the otel collector with tracing...
loop {
    // main loop...
}

This would result in a memory leak and I didn't see any traces being delivered. At first I was thinking that perhaps the otel collector was setup incorrectly or something along those lines, but in reality the underlying reason was much less straightforward. What would happen is that all tracing events would end up in some sort of channel (I think). The install_simple method had registered a task to pull from this channel, but since the runtime is single threaded and nothing within the main loop calls block_on on this runtime again, this task is never polled in the first place.

It would be great if console warning system had a warning for this kind of situation, if it doesn't yet ^^

nagisa avatar Dec 18 '21 16:12 nagisa

This is a great idea, we should definitely have something like that.

I think this will probably be easiest to implement once we add awareness of individual runtime instances to the console's data model (see #130). Then, the runtime can record whether or not it's running.

With the current data we have, though, we could probably have some kind of warning that's displayed if a large number of tasks have been spawned but none of them are being polled. The diagnostics we could provide for this are probably not as useful as the ones we could show once we actually are aware of runtime instances, though.

hawkw avatar Dec 18 '21 20:12 hawkw