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

fix: Avoid blocking on async runtime when resolving cloud scans #20750

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

Jesse-Bakker
Copy link
Contributor

No description provided.

@Jesse-Bakker Jesse-Bakker changed the title Avoid blocking on async runtime when resolving cloud scans Fix: Avoid blocking on async runtime when resolving cloud scans Jan 16, 2025
@Jesse-Bakker Jesse-Bakker changed the title Fix: Avoid blocking on async runtime when resolving cloud scans fix: Avoid blocking on async runtime when resolving cloud scans Jan 16, 2025
@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Jan 16, 2025
@Jesse-Bakker Jesse-Bakker force-pushed the fix/cloud-runtime-in-runtime branch from 9d7d20b to bc5e67f Compare January 16, 2025 14:12
@ritchie46 ritchie46 merged commit cf4b9bd into pola-rs:main Jan 16, 2025
18 of 20 checks passed
@evbo
Copy link

evbo commented Jan 28, 2025

Not sure if it's related but on 0.46.0 I just tried scanning s3 lazily and it panicked with:

panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-io-0.46.0/src/pl_async.rs:310:9:
can call blocking only when running on the multi-threaded runtime

example:

let s3_uri = format!("s3://{}/{}", bucket, key);
        let cloud_options = CloudOptions::default().with_aws(config_keys);
        let scan_args = ScanArgsParquet {
            cloud_options: Some(cloud_options),
            glob,
            ..ScanArgsParquet::default()
        };

        Ok(LazyFrame::scan_parquet(s3_uri, scan_args).unwrap())

@evbo
Copy link

evbo commented Jan 28, 2025

full backtrace:

stack backtrace:
0: rust_begin_unwind
at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
1: core::panicking::panic_fmt
at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
2: core::panicking::panic_display
at /usr/local/rustup/toolchains/1.83.0-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:264:5
3: tokio::runtime::scheduler::multi_thread::worker::block_in_place::panic_cold_display
at /usr/local/rustup/toolchains/1.83.0-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic.rs:100:13
4: tokio::runtime::scheduler::multi_thread::worker::block_in_place
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/multi_thread/worker.rs:444:9
5: tokio::runtime::scheduler::block_in_place::block_in_place
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/block_in_place.rs:20:5
6: tokio::task::blocking::block_in_place
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/task/blocking.rs:78:9
7: polars_io::pl_async::RuntimeManager::block_on_potential_spawn
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-io-0.46.0/src/pl_async.rs:310:9
8: polars_io::path_utils::expand_paths_hive::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-io-0.46.0/src/path_utils/mod.rs:235:17
9: polars_io::path_utils::expand_paths_hive
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-io-0.46.0/src/path_utils/mod.rs:330:25
10: polars_plan::plans::ir::scan_sources::ScanSources::expand_paths_with_hive_update
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/plans/ir/scan_sources.rs:121:56
11: polars_plan::plans::conversion::dsl_to_ir::to_alp_impl::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/plans/conversion/dsl_to_ir.rs:166:64
12: stacker::maybe_grow
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.17/src/lib.rs:55:9
13: polars_plan::plans::conversion::dsl_to_ir::to_alp_impl
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/plans/conversion/dsl_to_ir.rs:129:1
14: polars_plan::plans::conversion::dsl_to_ir::to_alp
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/plans/conversion/dsl_to_ir.rs:81:11
15: polars_plan::plans::optimizer::optimize
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/plans/optimizer/mod.rs:84:22
16: polars_lazy::frame::LazyFrame::optimize_with_scratch
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-lazy-0.46.0/src/frame/mod.rs:624:22
17: polars_lazy::frame::LazyFrame::prepare_collect_post_opt
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-lazy-0.46.0/src/frame/mod.rs:679:13
18: polars_lazy::frame::LazyFrame::_collect_post_opt
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-lazy-0.46.0/src/frame/mod.rs:700:49
19: polars_lazy::frame::LazyFrame::collect
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-lazy-0.46.0/src/frame/mod.rs:747:9
21: <core::pin::Pin

as core::future::future::Future>::poll
at /usr/local/rustup/toolchains/1.83.0-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:123:9
22: <core::pin::Pin

as core::future::future::Future>::poll
at /usr/local/rustup/toolchains/1.83.0-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:123:9
23: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:729:57
24: tokio::runtime::coop::with_budget
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/coop.rs:107:5
25: tokio::runtime::coop::budget
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/coop.rs:73:5
26: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:729:25
27: tokio::runtime::scheduler::current_thread::Context::enter
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:428:19
28: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:728:36
29: tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:807:68
30: tokio::runtime::context::scoped::Scoped::set
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/context/scoped.rs:40:9
31: tokio::runtime::context::set_scheduler::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/context.rs:180:26
32: std::thread::local::LocalKey::try_with
at /usr/local/rustup/toolchains/1.83.0-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:283:12
33: std::thread::local::LocalKey::with
at /usr/local/rustup/toolchains/1.83.0-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:260:9
34: tokio::runtime::context::set_scheduler
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/context.rs:180:9
35: tokio::runtime::scheduler::current_thread::CoreGuard::enter
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:807:27
36: tokio::runtime::scheduler::current_thread::CoreGuard::block_on
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:716:19
37: tokio::runtime::scheduler::current_thread::CurrentThread::block_on::{{closure}}
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:196:28
38: tokio::runtime::context::runtime::enter_runtime
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/context/runtime.rs:65:16
39: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/scheduler/current_thread/mod.rs:184:9
40: tokio::runtime::runtime::Runtime::block_on_inner
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/runtime.rs:368:47
41: tokio::runtime::runtime::Runtime::block_on
at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/runtime.rs:342:13
at /usr/local/rustup/toolchains/1.83.0-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
45: core::ops::function::FnOnce::call_once
at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

@evbo
Copy link

evbo commented Jan 28, 2025

@ritchie46 could this be an edge case not accounted for? The workaround is to instead:

let lf = tokio::task::spawn_blocking(|| {
        LazyFrame::scan_parquet(s3_uri, scan_args)
            .unwrap()
            .collect()
            .unwrap()
    })
    .await
    .unwrap().lazy();

But that's not great as it involves collect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants