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

Version 1.0.0 seems to be ignoring the sidekiq_role that is set. #191

Closed
codebycliff opened this issue Jan 25, 2018 · 16 comments
Closed

Version 1.0.0 seems to be ignoring the sidekiq_role that is set. #191

codebycliff opened this issue Jan 25, 2018 · 16 comments

Comments

@codebycliff
Copy link

After upgrading from 0.20.0 to 1.0.0, Sidekiq is now being started on all of our app servers, regardless of the role set. Downgrading to 0.20.0 fixes it so that it only starts Sidekiq on the server that has that role specified.

Our configuration is as follows:

config/deploy.rb

set :sidekiq_role, :worker

config/deploy/production.rb

server 'app01.example.com', user: 'deployer', roles: %w{app web db}
server 'app02.example.com', user: 'deployer', roles: %w{app worker}
server 'app04.example.com', user: 'deployer', roles: %w{app web}

Thanks in advance.

@Looooong
Copy link

Looooong commented Jan 26, 2018

It is because sidekiq_role has been changed to plural form sidekiq_roles.

This should have been documented in the CHANGELOG as a breaking change.

@codebycliff
Copy link
Author

Sounds good. Should it be added to the changelog as a breaking change now for people that haven't upgraded?

@rhomeister
Copy link

This was pretty painful for me to find and fix. A deprecation warning or something would have been appreciated....

@mensfeld
Copy link

mensfeld commented Feb 11, 2018

Despite changing that it still does not work :/

Sidekiq actions are not running at all for deployment flow...

@mensfeld
Copy link

Guys any news on that one? I could help if needed

@Looooong
Copy link

Mine works fine. Do you set the role on the server properly?

@jsantos
Copy link
Contributor

jsantos commented Mar 27, 2018

The same is happening to me. Other gems recognize my roles just fine, but this one is not recognizing them, which turns out to be a nightmare since the process number is not interpreted correctly.

@Looooong I'm defining the roles using the server-based syntax, are you doing it in a different way by any chance?

@Looooong
Copy link

Looooong commented Mar 28, 2018

I use Capistrano 3.10.1 and Capistrano Sidekiq 1.0.0. Here is how I config the Sidekiq:

set :sidekiq_roles, :sidekiq
set :sidekiq_config, -> { File.join(current_path, 'config', 'sidekiq.yml') }

server 'host', user: fetch(:user), roles: %w[app migration sidekiq], primary: true

@jsantos
Copy link
Contributor

jsantos commented Mar 28, 2018

@Looooong yeah I'm using the exact same versions.

I believe the issue only occurs when there is more than one role (I control the number of sidekiq processes based on the role by using <role>_processes.

@mensfeld
Copy link

@jsantos same here - exactly the same case.

@Looooong
Copy link

You guys should take a look at sidekiq.rake:142 to see if there is any problem with the code. I don't see any problem with it, perhaps you can.

@jsantos
Copy link
Contributor

jsantos commented Mar 29, 2018

Guess I've found the issue. After much debugging I figured out the issue lies exactly where @Looooong pointed out.

The .select! on sidekiq_roles.select! { |role| host.roles.include?(role) } is mutating :sidekiq_roles. So, for the first role the list of pidfiles is correctly returned, but the same won't happen to further method calls.

Example:

set :sidekiq_pid, File.join(shared_path, 'tmp', 'pids', 'sidekiq.pid')
set :sidekiq_roles, [:master, :slave]
set :master_processes, 1
set :slave_processes, 2

# On the first host (host.roles = [:master]): 
> pid_files
[
    [0] "app/shared/tmp/pids/sidekiq-0.pid"
]

# On the second host (roles = [:slave]):
> pid_files
[]

Without mutating the sidekiq_roles variable, we get the following:

# On the first host (host.roles = [:master]): 
> pid_files
[
    [0] "app/shared/tmp/pids/sidekiq-0.pid"
]

# On the second host (roles = [:slave]):
> pid_files
[
    [0] "app/shared/tmp/pids/sidekiq-0.pid",
    [1] "app/shared/tmp/pids/sidekiq-1.pid"
]

Since the method is used every time we call each_process_with_index, this kinda screws things up.

So on this line, we should use:

sidekiq_roles = sidekiq_roles.select { |role| host_roles.include?(role) }

To avoid the mutation of sidekiq_roles.

I'll issue a PR to fix this.

@Looooong
Copy link

Good finding there! I have never thought that sidekiq_roles = Array(fetch(:sidekiq_roles)) would return the original array.

@jsantos
Copy link
Contributor

jsantos commented Mar 29, 2018

@Looooong Yeah, that's why it took so long to debug.

For reference:

[1] pry(main)> sidekiq_roles = [:master, :slave]
[
    [0] :master,
    [1] :slave
]
[2] pry(main)> roles = Array(sidekiq_roles)
[
    [0] :master,
    [1] :slave
]
[3] pry(main)> roles.select! {|r| r == :master}
[
    [0] :master
]
[4] pry(main)> roles
[
    [0] :master
]
[5] pry(main)> sidekiq_roles
[
    [0] :master
]
``

@mensfeld
Copy link

@jsantos any chance on releasing 1.0.1?

@jsantos
Copy link
Contributor

jsantos commented Apr 1, 2018

@mensfeld I just issued the PR, but don't have the power to merge it... @seuros might need to weight in

seuros added a commit that referenced this issue Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants