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

#<FiberError: fiber called across threads> #2924

Open
ianeinser opened this issue May 10, 2021 · 0 comments
Open

#<FiberError: fiber called across threads> #2924

ianeinser opened this issue May 10, 2021 · 0 comments

Comments

@ianeinser
Copy link

ianeinser commented May 10, 2021

Hi there,

we got this errors when trying to run multiple engine drivers in upstream.rb. It seems that the method Thread.new doesnt play nicely with Eventmachine Symphony which is based on Fiber.

this is the full error.

#<Thread:0x000055a3665aa410@/home/app/app/workers/daemons/upstream.rb:8 run> terminated with exception (report_on_exception is true):
(eval):8:in resume': fiber called across threads (FiberError) from (eval):8:in block in get'
from /opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb:151:in set_deferred_status' from /opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb:191:in succeed'
from /opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/client.rb:113:in unbind' from /opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/client.rb:71:in on_request_complete'
from /opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:204:in block in post_init' from /opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:219:in <<'
from /opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:219:in receive_data' from /opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:26:in receive_data'
from /opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in run_machine' from /opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in run'
from /opt/vendor/bundle/ruby/2.6.0/gems/em-synchrony-1.0.6/lib/em-synchrony.rb:39:in synchrony' from /home/app/app/workers/daemons/upstream.rb:12:in process'
from /home/app/app/workers/daemons/upstream.rb:8:in block (3 levels) in run' {"level":"ERROR","time":"2021-05-10 03:31:41","message":"#<FiberError: fiber called across threads>"} {"level":"ERROR","time":"2021-05-10 03:31:41","message":"(eval):8:in resume'\n(eval):8:in block in get'\n/opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb:151:in set_deferred_status'\n/opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/deferrable.rb:191:in succeed'\n/opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/client.rb:113:in unbind'\n/opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/client.rb:71:in on_request_complete'\n/opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:204:in block in post_init'\n/opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:219:in <<'\n/opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:219:in receive_data'\n/opt/vendor/bundle/ruby/2.6.0/gems/em-http-request-1.1.7/lib/em-http/http_connection.rb:26:in receive_data'\n/opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in run_machine'\n/opt/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in run'\n/opt/vendor/bundle/ruby/2.6.0/gems/em-synchrony-1.0.6/lib/em-synchrony.rb:39:in synchrony'\n/home/app/app/workers/daemons/upstream.rb:12:in process'\n/home/app/app/workers/daemons/upstream.rb:8:in block (3 levels) in run'"}

It seems that Fiber and Thread do not play well with each other. Hence we replace Thread.new with Fiber.new but upstream can only read one engine driver and ignore the rest. Feedback and suggestions are appreciated.

openware original code:
Engine.all.map { |e| Thread.new { process(e) } }.map(&:join)

we change to:
Engine.all.map { |e| Fiber.new { process(e) } }.map(&:join)

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant