Skip to content

Dependency registration is not thread-safe #20

Description

@KevinBrowne

Sinject::Conatainer#register does a check and set that is not protected in a critical section, making it vulnerable to race conditions.

Broadly, the method looks like this:

def register
  raise 'Duplicate key' if key_exists?

  do_registration
end

If you attempt to register more than one dependency with the same key, the #register method should raise a duplicate key error. However, two concurrent calls to #register can both pass the duplicate key check, and proceed to the registration step, with the last one "winning". It would be better for the container to always raise the error rather than behave unpredictably, however rare the circumstances.

This is difficult to reliably reproduce.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions