chef-boneyard / opscode-pushy-client

Client API for Pushy
Apache License 2.0
12 stars 14 forks source link

`synchronize': can't be called from trap context #130

Open jeremymv2 opened 7 years ago

jeremymv2 commented 7 years ago

Description

When terminating after receiving a signal such as SIGTERM, SIGINT or SIGKILL, pushy does not trap and handle correctly:

INFO: [node] Received server heartbeat (sequence #251) logging 1/3
received TERM, shutting down
INFO: [node] Stopping client ...
/opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/protocol_handler.rb:175:in `synchronize': can't be called from trap context (ThreadError)
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/protocol_handler.rb:175:in `stop'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client.rb:110:in `stop'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:115:in `shutdown'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:151:in `block (2 levels) in run_application'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:164:in `call'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:164:in `sleep'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:164:in `run_application'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:58:in `run'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/bin/pushy-client:8:in `<top (required)>'
    from /opt/push-jobs-client/bin/pushy-client:55:in `load'
    from /opt/push-jobs-client/bin/pushy-client:55:in `<main>'

This seems to be related to a change in ruby 2.x: https://bugs.ruby-lang.org/issues/7917

Here's an example pattern used to handle signals differently: https://github.com/resque/resque-scheduler/pull/344

Push Jobs Client Version

2.3.0

Platform Version

Centos 6,7

Replication Case

Just start the process in the foreground: /opt/push-jobs-client/bin/pushy-client -l info -L /var/log/chef/push-jobs-client.log -c /etc/chef/push-jobs-client.rb

Then either ctrl-c or send it a signal with kill -s SIGTERM pid and you'll see the error above.

Note: the runit and upstart services won't log this error since it's coming from stderr and stderr needs to be enabled in the service to show up in the logs.

Stacktrace

/opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/protocol_handler.rb:175:in `synchronize': can't be called from trap context (ThreadError)
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/protocol_handler.rb:175:in `stop'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client.rb:110:in `stop'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:115:in `shutdown'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:151:in `block (2 levels) in run_application'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:164:in `call'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:164:in `sleep'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/lib/pushy_client/cli.rb:164:in `run_application'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:58:in `run'
    from /opt/push-jobs-client/embedded/lib/ruby/gems/2.1.0/gems/opscode-pushy-client-2.1.4/bin/pushy-client:8:in `<top (required)>'
    from /opt/push-jobs-client/bin/pushy-client:55:in `load'
    from /opt/push-jobs-client/bin/pushy-client:55:in `<main>'