Skip to content

Starting a container in Async block fails #44

@orlando-labs

Description

@orlando-labs

Hi, @ioquatix.
Starting a container from Async block fails after container instance block completion or on first async code encounter.

app % irb
3.3.6 :001 > require 'async'
 => true 
3.3.6 :002 > require 'async/container'
 => true 
3.3.6 :003 > class Controller < Async::Container::Controller
3.3.6 :004 >   def create_container
3.3.6 :005 >     Async::Container::Forked.new
3.3.6 :006 >     # or Async::Container::Threaded.new
3.3.6 :007 >     # or Async::Container::Hybrid.new
3.3.6 :008 >   end
3.3.6 :009 >    
3.3.6 :010 >   def setup(container)
3.3.6 :011 >     container.run count: 1, restart: false do |instance|
3.3.6 :012 >       p 'ohai'
3.3.6 :013 >     end
3.3.6 :014 >   end
3.3.6 :015 > end
 => :setup 
3.3.6 :016 > Controller.new.start
  0.0s     info: Controller [oid=0xb644] [ec=0xb658] [pid=94561] [2025-09-18 10:19:38 +0300]
               | Controller starting...
"ohai"
 0.12s     info: Async::Container::Notify::Console [oid=0xb6a8] [ec=0xb658] [pid=94561] [2025-09-18 10:19:38 +0300]
               | {:ready=>true, :size=>0}
 0.12s     info: Controller [oid=0xb644] [ec=0xb658] [pid=94561] [2025-09-18 10:19:38 +0300]
               | Controller started...
 => nil 
3.3.6 :017 > Async { Controller.new.start }
10.07s     info: Controller [oid=0xe9e8] [ec=0xe9fc] [pid=94561] [2025-09-18 10:19:48 +0300]
               | Controller starting...
"ohai"
/Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:212:in `raise': Task was stopped (Async::Stop)
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:212:in `raise'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/task.rb:318:in `stop'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/node.rb:272:in `terminate'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:140:in `block in terminate'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/list.rb:298:in `each'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/list.rb:311:in `each'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/list.rb:180:in `each'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:139:in `terminate'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:150:in `block in close'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:528:in `block in run_loop'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:525:in `handle_interrupt'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:525:in `run_loop'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:149:in `close'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/reactor.rb:29:in `scheduler_close'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:102:in `fork'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:102:in `block in fork'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:146:in `initialize'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:101:in `new'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:101:in `fork'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:268:in `start'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/generic.rb:176:in `block in spawn'
10.18s    error: Async::Container::Forked [oid=0xea38] [ec=0xea4c] [pid=94561] [2025-09-18 10:19:48 +0300]
               | {
               |   "status": "pid 94569 exit 1"
               | }
10.18s    error: Async::Container::Notify::Console [oid=0xb6a8] [ec=0xe9fc] [pid=94561] [2025-09-18 10:19:48 +0300]
               | {:status=>"Container failed to start!"}
10.18s     info: Async::Container::Group [oid=0xea60] [ec=0xe9fc] [pid=94561] [2025-09-18 10:19:48 +0300]
               | Sending terminate to 0 running processes...
10.18s     info: Async::Container::Group [oid=0xea60] [ec=0xe9fc] [pid=94561] [2025-09-18 10:19:48 +0300]
               | Sending terminate to 0 running processes...
10.18s     warn: Async::Task [oid=0xea74] [ec=0xe9fc] [pid=94561] [2025-09-18 10:19:48 +0300]
               | Task may have ended with unhandled exception.
               |   Async::Container::SetupError: Could not create container!
               |   → /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/controller.rb:139 in `restart'
               |     /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/controller.rb:95 in `start'
               |     (irb):17 in `block in <top (required)>'
               |     /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/task.rb:207 in `block in run'
               |     /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/task.rb:452 in `block in schedule'
3.3.6 :018 > class Controller < Async::Container::Controller
3.3.6 :019 >   def create_container
3.3.6 :020 >     Async::Container::Forked.new
3.3.6 :021 >     # or Async::Container::Threaded.new
3.3.6 :022 >     # or Async::Container::Hybrid.new
3.3.6 :023 >   end
3.3.6 :024 >    
3.3.6 :025 >   def setup(container)
3.3.6 :026 >     container.run count: 1, restart: false do |instance|
3.3.6 :027 >       Async { |task| task.sleep 1; p 'end' }
3.3.6 :028 >     end
3.3.6 :029 >   end
3.3.6 :030 > end
 => :setup 
3.3.6 :031 > Async { Controller.new.start }
   22m     info: Controller [oid=0x55b18] [ec=0x55b2c] [pid=94561] [2025-09-18 10:42:16 +0300]
               | Controller starting...
/Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:212:in `raise': Task was stopped (Async::Stop)
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:212:in `raise'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/task.rb:318:in `stop'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/node.rb:272:in `terminate'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:140:in `block in terminate'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/list.rb:298:in `each'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/list.rb:311:in `each'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/list.rb:180:in `each'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:139:in `terminate'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:150:in `block in close'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:528:in `block in run_loop'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:525:in `handle_interrupt'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:525:in `run_loop'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/scheduler.rb:149:in `close'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/reactor.rb:29:in `scheduler_close'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:102:in `fork'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:102:in `block in fork'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:146:in `initialize'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:101:in `new'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:101:in `fork'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/forked.rb:268:in `start'
	from /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/generic.rb:176:in `block in spawn'
   22m    error: Async::Container::Forked [oid=0x55b68] [ec=0x55b7c] [pid=94561] [2025-09-18 10:42:17 +0300]
               | {
               |   "status": "pid 95167 exit 1"
               | }
   22m    error: Async::Container::Notify::Console [oid=0xb6a8] [ec=0x55b2c] [pid=94561] [2025-09-18 10:42:17 +0300]
               | {:status=>"Container failed to start!"}
   22m     info: Async::Container::Group [oid=0x55b90] [ec=0x55b2c] [pid=94561] [2025-09-18 10:42:17 +0300]
               | Sending terminate to 0 running processes...
   22m     info: Async::Container::Group [oid=0x55b90] [ec=0x55b2c] [pid=94561] [2025-09-18 10:42:17 +0300]
               | Sending terminate to 0 running processes...
   22m     warn: Async::Task [oid=0x55ba4] [ec=0x55b2c] [pid=94561] [2025-09-18 10:42:17 +0300]
               | Task may have ended with unhandled exception.
               |   Async::Container::SetupError: Could not create container!
               |   → /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/controller.rb:139 in `restart'
               |     /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-container-0.27.0/lib/async/container/controller.rb:95 in `start'
               |     (irb):31 in `block in <top (required)>'
               |     /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/task.rb:207 in `block in run'
               |     /Users/slowpilot/.rvm/gems/ruby-3.3.6/gems/async-2.32.0/lib/async/task.rb:452 in `block in schedule'

The same approach worked with a previous version of the async-controller, but unfortunately, I'm unable to specify which exact version it was.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions