ruby-concurrency/concurrent-ruby · error · ArgumentError
#{@fallback_policy} is not a valid fallback policy
Error message
#{@fallback_policy} is not a valid fallback policy What it means
On MRI, ThreadPoolExecutor validates opts[:fallback_policy] (default :abort) against FALLBACK_POLICIES (:abort, :discard, :caller_runs) and raises ArgumentError otherwise. The policy governs tasks posted after shutdown; Symbols are required, so Strings and typos fail.
Source
Thrown at lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:155
# @!macro thread_pool_executor_method_prune_pool
def prune_pool
deprecated "#prune_pool has no effect and will be removed in next the release, see https://github.com/ruby-concurrency/concurrent-ruby/pull/1082."
end
private
# @!visibility private
def ns_initialize(opts)
@min_length = opts.fetch(:min_threads, DEFAULT_MIN_POOL_SIZE).to_i
@max_length = opts.fetch(:max_threads, DEFAULT_MAX_POOL_SIZE).to_i
@idletime = opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT).to_i
@max_queue = opts.fetch(:max_queue, DEFAULT_MAX_QUEUE_SIZE).to_i
@synchronous = opts.fetch(:synchronous, DEFAULT_SYNCHRONOUS)
@fallback_policy = opts.fetch(:fallback_policy, :abort)
raise ArgumentError.new("`synchronous` cannot be set unless `max_queue` is 0") if @synchronous && @max_queue > 0
raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICIES.include?(@fallback_policy)
raise ArgumentError.new("`max_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}") if @max_length < DEFAULT_MIN_POOL_SIZE
raise ArgumentError.new("`max_threads` cannot be greater than #{DEFAULT_MAX_POOL_SIZE}") if @max_length > DEFAULT_MAX_POOL_SIZE
raise ArgumentError.new("`min_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}") if @min_length < DEFAULT_MIN_POOL_SIZE
raise ArgumentError.new("`min_threads` cannot be more than `max_threads`") if min_length > max_length
@pool = [] # all workers
@ready = [] # used as a stash (most idle worker is at the start)
@queue = [] # used as queue
# @ready or @queue is empty at all times
@scheduled_task_count = 0
@completed_task_count = 0
@largest_length = 0
@workers_counter = 0
@ruby_pid = $$ # detects if Ruby has forked
end
# @!visibility private
def ns_limited_queue?View on GitHub (pinned to 0b88d5ff75)
Solutions
- Use exactly :abort, :discard or :caller_runs as Symbols
- Normalize strings early: policy = raw.to_s.downcase.to_sym
- Validate against Concurrent::AbstractExecutorService::FALLBACK_POLICIES before constructing
Example fix
# before Concurrent::ThreadPoolExecutor.new(fallback_policy: 'discard') # after Concurrent::ThreadPoolExecutor.new(fallback_policy: :discard)
Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = Concurrent::AbstractExecutorService::FALLBACK_POLICIES
policy = cfg.fetch(:fallback_policy, :abort).to_s.to_sym
raise ArgumentError, "fallback_policy must be one of #{ALLOWED}" unless ALLOWED.include?(policy)
Concurrent::ThreadPoolExecutor.new(fallback_policy: policy) Type guard
def valid_fallback_policy?(v) Concurrent::AbstractExecutorService::FALLBACK_POLICIES.include?(v) end
Try / catch
begin
Concurrent::ThreadPoolExecutor.new(fallback_policy: policy)
rescue ArgumentError => e
raise unless e.message.end_with?('is not a valid fallback policy')
Concurrent::ThreadPoolExecutor.new(fallback_policy: :abort)
end Prevention
- Convert YAML/JSON/ENV strings to Symbols at load time
- Test config parsing with string values to catch Symbol/String drift
- Validate the whole opts hash once before pool construction
When it happens
Trigger: Concurrent::ThreadPoolExecutor.new(fallback_policy: 'discard') on MRI; fallback_policy: :ignore (typo/invalid); values loaded from YAML, JSON or ENV that arrive as strings.
Common situations: Serialized config producing Strings; policy names copied from other libraries; per-environment defaults where one environment has a typo.
Related errors
- number of threads must be greater than zero
- `synchronous` cannot be set unless `max_queue` is 0
- `max_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}
- `max_threads` cannot be greater than #{DEFAULT_MAX_POOL_SIZE
- `min_threads` cannot be less than #{DEFAULT_MIN_POOL_SIZE}
AI-assisted analysis of ruby-concurrency/concurrent-ruby@0b88d5ff75 (2026-08-21).
Data as JSON: /api/errors/5961729f8abead81.
Report an issue: GitHub.