crepererum commented on code in PR #14028: URL: https://github.com/apache/datafusion/pull/14028#discussion_r1905787146
########## datafusion/core/src/datasource/physical_plan/file_stream.rs: ########## @@ -478,7 +478,12 @@ impl<F: FileOpener> FileStream<F> { reader, )), partition_values, - } + }; + // Return control to the runtime when we're ready to open the next file + // to prevent uncancellable queries in scenarios with many large files. + // This functions similarly to a `tokio::task::yield_now()`. + cx.waker().wake_by_ref(); + return Poll::Pending; Review Comment: For the multi-thread RT (which is the only thing we really care about, I think it's NOT instantly calling `wake_by_ref` instantly: 1. `yield_now`: https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/task/yield_now.rs#L57 2. `context::defer`: https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/runtime/context.rs#L166-L177 3. `with_scheduler`: https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/runtime/context.rs#L183-L195 4. (via some indirection) `Context::defer`: https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/runtime/scheduler/mod.rs#L287-L289 5. (via some indirection) `Context::defer` (different `Context` this time): https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/runtime/scheduler/multi_thread/worker.rs#L766-L768 6. `Defer::defer`: https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/runtime/scheduler/defer.rs#L15-L26 7. The deferred threads are woken in two places ([1](https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/runtime/scheduler/multi_thread/worker.rs#L513-L516), [2](https://github.com/tokio-rs/tokio/blob/bd3e8577377a2b684b50fc0cb50d98f03ad09703/tokio/src/runtime/scheduler/multi_thread/worker.rs#L751)) for which the 2nd one seems relevant. The actual waking will happen when the worker is -- I think -- unparked after a "park timeout". This is definitely long after `Pending` is returned, because the thread that is returning `Pending` is the very same worker, i.e. it cannot possibly be parked at this point in time. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org