-
Notifications
You must be signed in to change notification settings - Fork 37
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
Unable to save backup file. Exception thrown Errno::ENOENT #108
Comments
Just to make everything work for puma clustered/single modes, sidekiq, rails console & other libs I did next config like a workaround: in # frozen_string_literal: true
require "unleash"
require "socket"
require "securerandom"
require "forwardable"
module UNLEASH
FakeClient = Struct.new(:turn_on) do
def enabled?(*)
turn_on
end
def if_enabled(*)
yield if turn_on
end
def shutdown; end
def shutdown!; end
end
class << self
extend Forwardable
def_delegators :client,
:enabled?,
:if_enabled,
:get_variant,
:shutdown,
:shutdown!
def preload
@client = if ENV.fetch("UNLEASH_TOKEN", nil) && ENV.fetch("UNLEASH_URL", nil)
Unleash::Client.new(
app_name: "#{ENV.fetch("DD_SERVICE", nil)}-#{SecureRandom.uuid}",
environment: ENV.fetch("DD_ENV", nil),
instance_id: Socket.gethostname,
url: ENV.fetch("UNLEASH_URL", nil),
custom_http_headers: { Authorization: ENV.fetch("UNLEASH_TOKEN", nil) }
)
else
FakeClient.new(false)
end
end
def client
@client || preload
end
end
end in require_relative File.expand_path("../lib/unleash.rb", __dir__) # if not --preload
# unleash
on_worker_boot do
UNLEASH.preload
end
on_worker_shutdown do
UNLEASH.shutdown
end in require_relative File.expand_path("../../lib/unleash.rb", __dir__)
Rails.application.console do
UNLEASH.preload
end
Sidekiq.configure_server do |config|
config.on(:startup) do
UNLEASH.preload
end
config.on(:shutdown) do
UNLEASH.shutdown
end
end So now I can call |
But such configuration looks awful, so would be great to find some more convenient way of |
I also faced same issue with Unicorn server. Worker processes use same file for backup and throw error as posted by creator of this issue. The potential workaround is to set different backup file for each worker process: after_worker_ready do |server, worker|
app_name = Unleash.configuration.app_name
Unleash.configuration.backup_file = Dir.tmpdir + "/unleash-#{app_name}-#{worker.nr}-repo.json"
::UNLEASH = Unleash::Client.new
end |
Thanks for this, I've also got it working in the worker boot block on_worker_boot do |index|
Unleash.configuration.backup_file = Dir.tmpdir + "/unleash-#{index}-repo.json"
Rails.configuration.unleash = Unleash::Client.new
end |
Describe the bug
Hi there, I face some issues when I use puma in clustered mode (following the documentation in readme)
But I would list here a bit more issues:
clients
(multi-process app on a single machine - puma clustered mode for instance) - all processes have the same backup_file https://github.com/Unleash/unleash-client-ruby/blob/main/lib/unleash/configuration.rb#L47, only if you name application differently I can get separated backup_file so I won’t face withno such file or dir
error.This error comes from there on File.rename. The only mechanism you use is Mutex, but it does not work for multiple processes (only for threads inside a single process)
backup_file is overwritten [always](https://github.com/Unleash/unleash-client-ruby/blob/main/lib/unleash/client.rb#L15, https://github.com/Unleash/unleash-client-ruby/blob/main/lib/unleash/configuration.rb#L32), so I cannot define it explicitly.
we have puma in clustered mode on prod and in a single-mode in dev, which means I cannot use the same config on both ENVs according to the configuration section on the readme.
Steps to reproduce the bug
system: MacOS BigSur 11.4
setup unleash according to the readme for puma (clustered mode) https://github.com/Unleash/unleash-client-ruby/blob/c745ed4569b5e83498d22e0fbf618e8eb6ce2002/README.md#with-preload_app
bundle exec puma -w 3 --preload
Expected behavior
No errors should be thrown.
Logs, error output, etc.
Screenshots
No response
Additional context
No response
Unleash version
4.2.1
Subscription type
No response
Hosting type
No response
SDK information (language and version)
ruby, RoR, Sidekiq, Puma
The text was updated successfully, but these errors were encountered: