Files
windmill/backend/windmill-worker/src/lib.rs
T
Ruben FiszelandClaude Opus 4.6 6d58d1a74d fix: pipeline DISCARD ALL with first query on cached pg connections (#8707)
* perf: pipeline DISCARD ALL with first query on cached pg connections

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* perf: use RESET ALL instead of DISCARD ALL for lighter session reset

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add integration test for pg session reset on cached connections

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: release MutexGuard before caching so pg connection cache actually works

The old code shadowed the MutexGuard variable without dropping it, so
try_lock() in the post-query caching path always failed — connection
caching was effectively dead code. Restructure to explicitly drop the
guard before connecting.

Also adds a CACHE_HITS counter and clear_pg_cache() helper so the
integration test can verify the cached-connection path is exercised.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add single-worker session isolation test for SET ROLE + search_path

Pushes 3 jobs into the queue before starting the worker so a single
worker processes them all sequentially (matching production). Verifies
SET ROLE and SET search_path do not leak between jobs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: add RESET ROLE to session reset (RESET ALL does not undo SET ROLE)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use DISCARD ALL for full session reset and retry on stale connections

- Switch from pipelined RESET ROLE; RESET ALL to eager DISCARD ALL when
  validating cached connections. This resets everything: role, GUCs,
  prepared statements, temp tables, advisory locks, LISTEN registrations.
- DISCARD ALL also serves as a health check: if it fails, the stale
  connection is discarded and a fresh one is created transparently.
- Extract new_pg_connection() helper to avoid duplicating the connect +
  spawn-connection-task logic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: add 100-job single-worker cache stress test

Runs 100 varied PG jobs (plain SELECTs, SET ROLE, SET search_path,
multi-statement) through one worker. Verifies all succeed, 99 hit the
cache, and no session state leaks between jobs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 22:16:48 +00:00

112 lines
2.9 KiB
Rust

#[cfg(all(feature = "enterprise", feature = "bigquery"))]
mod bigquery_executor;
#[cfg(all(feature = "enterprise", feature = "mssql"))]
mod mssql_executor;
#[cfg(feature = "enterprise")]
mod snowflake_executor;
mod agent_workers;
#[cfg(feature = "python")]
mod ansible_executor;
mod bash_executor;
mod pwsh_executor;
#[cfg(feature = "java")]
mod java_executor;
#[cfg(feature = "ruby")]
mod ruby_executor;
#[cfg(feature = "rlang")]
mod r_executor;
mod ai;
mod ai_executor;
mod bun_executor;
pub mod common;
mod config;
mod csharp_executor;
#[cfg(feature = "private")]
mod dedicated_worker_ee;
mod dedicated_worker_oss;
mod deno_executor;
#[cfg(feature = "duckdb")]
mod duckdb_executor;
mod global_cache;
mod go_executor;
mod graphql_executor;
mod handle_child;
pub mod job_logger;
#[cfg(feature = "private")]
pub mod job_logger_ee;
mod job_logger_oss;
mod js_eval;
pub mod memory_common;
#[cfg(feature = "private")]
pub mod memory_ee;
pub mod memory_oss;
#[cfg(feature = "mysql")]
mod mysql_executor;
#[cfg(feature = "nu")]
mod nu_executor;
#[cfg(feature = "oracledb")]
mod oracledb_executor;
#[cfg(feature = "private")]
pub mod otel_ee;
mod otel_oss;
#[cfg(all(feature = "private", feature = "enterprise"))]
mod otel_tracing_proxy_ee;
mod otel_tracing_proxy_oss;
pub mod pg_executor;
#[cfg(feature = "php")]
mod php_executor;
mod prepare_deps;
#[cfg(feature = "python")]
mod python_executor;
#[cfg(feature = "python")]
mod python_versions;
pub mod result_processor;
#[cfg(feature = "rust")]
mod rust_executor;
mod sanitized_sql_params;
mod schema;
pub mod sql_utils;
mod universal_pkg_installer;
#[cfg(feature = "private")]
mod volume_ee;
mod volume_oss;
pub mod wac_executor;
mod worker;
mod worker_flow;
mod worker_lockfiles;
mod worker_utils;
#[cfg(all(feature = "private", feature = "enterprise"))]
pub use otel_tracing_proxy_ee::start_jobs_otel_tracing;
#[cfg(all(feature = "private", feature = "enterprise", feature = "deno_core"))]
pub use otel_tracing_proxy_ee::{load_internal_otel_exporter, DENO_OTEL_INITIALIZED};
pub use worker::*;
pub use bun_executor::{
build_loader, compute_bundle_local_and_remote_path, get_common_bun_proc_envs,
install_bun_lockfile, prebundle_bun_script, prepare_job_dir, LoaderMode,
BUN_DEDICATED_WORKER_ARGS, RELATIVE_BUN_BUILDER, RELATIVE_BUN_LOADER,
};
#[cfg(any(feature = "private", test))]
pub use bun_executor::{
compute_ts_codegen, generate_multi_script_wrapper, TsScriptCodegen, TsScriptEntry,
};
#[cfg(any(feature = "private", test))]
pub use deno_executor::generate_dedicated_worker_wrapper as generate_deno_dedicated_worker_wrapper;
pub use deno_executor::{generate_deno_lock, DENO_UNSTABLE_ARGS};
pub use prepare_deps::run_prepare_deps_cli;
#[cfg(all(feature = "python", any(feature = "private", test)))]
pub use python_executor::{
compute_py_codegen, generate_multi_script_wrapper as generate_py_multi_script_wrapper,
PyScriptCodegen, PyScriptEntry,
};
#[cfg(feature = "python")]
pub use python_versions::PyV;