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

Race condition for creating ConnectionPool? #49

Open
mlangenberg opened this issue Oct 20, 2013 · 3 comments
Open

Race condition for creating ConnectionPool? #49

mlangenberg opened this issue Oct 20, 2013 · 3 comments

Comments

@mlangenberg
Copy link

https://github.com/arthurnn/apn_sender/blob/master/lib/apn/connection.rb#L5

As you probably know, Sidekiq runs in a multithreaded environment. I believe calling APN.notify_sync from multiple threads will still cause a race condition for the conditional assignment and creation of the client.

    def connection_pool
      @pool ||= ConnectionPool.new(size: (pool_size || 1), timeout: (pool_timeout || 5)) do
        APN::Client.new(host: host,
                        port: port,
                        certificate: certificate,
                        password: password)
      end
    end

    def with_connection(&block)
      connection_pool.with(&block)
    end

APN::Client itself is already lazily opening a socket connect, so in my opinion it does not hurt to initialize the ConnectionPool in an earlier stage.

Another interesting idea is to see if the APN::Client could be a Celluloid::Actor of its own.

@thbar
Copy link

thbar commented Apr 30, 2014

Any update on this? I'm discovering apn_sender and wonder if I can use it safely with Sidekiq (which it seems to support).

@arthurnn
Copy link
Owner

This is a race-condition that theoretically could happen, but I was not able to simulate yet... we use in production with Sidekiq without any problems so far.

@thbar
Copy link

thbar commented May 1, 2014

Thanks for the reply!

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

3 participants