Bug 745561

Summary: Failure creating a consumer - duplicate key
Product: [Retired] Pulp Reporter: Jeff Weiss <jweiss>
Component: user-experienceAssignee: Jason Connor <jconnor>
Status: CLOSED CURRENTRELEASE QA Contact: Preethi Thomas <pthomas>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 1.0.0CC: dajohnso, jconnor, mmccune, skarmark
Target Milestone: ---Keywords: Triaged
Target Release: Sprint 29   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-02-24 20:13:43 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Jeff Weiss 2011-10-12 17:37:48 UTC
Description of problem:
Creating a consumer in Katello causes the duplicate key error below.  It may have something to do with creating two consumers in rapid succession.
 
from IRC: 
<linear> hmmm  [12:57]
<linear> jweiss: actually this bug came from registering a consumer  [12:58]
<linear> which is odd  [12:59]
<linear> I wonder if we hit a race condition here
<linear> This is what the code looks like  [13:00]
<linear>         permission = self.permission(resource)
<linear>         if permission is None:
<linear>             permission = self.create(resource)
<linear> and it's exploding the the create
<linear> so it asks the db got the permission doc, doesn't get one, tries to
         create one, and gets a duplicate key error
<linear> I'll look into mongo and see if they have an atomic equivalent of
         that operation  [13:01]
<linear> in the meantime, jweiss, would you file a bug?


Version-Release number of selected component (if applicable):
pulp-0.0.237-4.fc14.noarch

How reproducible:


Steps to Reproduce:
1. 
2.
3.
  
Actual results:


Expected results:


Additional info:
2011-10-12 12:17:19,566 11267:140401121941248: pulp.server.webservices.controllers.decorators:ERROR: decorators:52 Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pulp/server/webservices/controllers/decorators.py", line 48, in report_error
    return method(self, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pulp/server/webservices/controllers/decorators.py", line 127, in _auth_decorator
    value = method(self, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pulp/server/webservices/controllers/consumers.py", line 104, in POST
    add_user_to_role(consumer_users_role, user['login'])
  File "/usr/lib/python2.7/site-packages/pulp/server/auth/authorization.py", line 398, in add_user_to_role
    _permission_api.grant(resource, user, operations)
  File "/usr/lib/python2.7/site-packages/pulp/server/api/permission.py", line 102, in grant
    permission = self._get_or_create(resource)
  File "/usr/lib/python2.7/site-packages/pulp/server/api/permission.py", line 79, in _get_or_create
    permission = self.create(resource)
  File "/usr/lib/python2.7/site-packages/pulp/server/api/permission.py", line 36, in create
    self.collection.insert(permission, safe=True)
  File "/usr/lib/python2.7/site-packages/pulp/server/db/connection.py", line 80, in retry
    return method(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 270, in insert
    check_keys, safe, kwargs), safe)
  File "/usr/lib64/python2.7/site-packages/pymongo/connection.py", line 642, in _send_message
    return self.__check_response_to_last_error(response)
  File "/usr/lib64/python2.7/site-packages/pymongo/connection.py", line 611, in __check_response_to_last_error
    raise DuplicateKeyError(error["err"])
DuplicateKeyError: E11000 duplicate key error index: pulp_database.permissions.$resource_-1  dup key: { : "/consumers/" }

2011-10-12 12:17:19,696 11267:140401130333952: gofer.rmi.policy:INFO: policy:236 sent (391df21b-2e6c-4f77-9f84-029ef8edb150):
{
  "classname": "Consumer",
  "kws": {},
  "args": [],
  "method": "unregistered"
}

Comment 1 Jason Connor 2011-10-26 04:41:36 UTC
Added a try/except block around create and then passed back the find results

Comment 2 Jeff Ortel 2011-10-27 03:22:19 UTC
build 0.242-2

Comment 3 Jason Connor 2011-11-10 21:31:09 UTC
This is actually a very difficult bug to reproduce as it was a timing issue. Basically you want a clean install of pulp (no permissions granted, no consumers) and then simultaneously create two consumer and see if you get the error.

Unfortunately, no error is not indicative of no bug. You'll have to hammer the server with the following:

1. fresh install
2. create 2 consumers from two different shells, threads, or clients
3. repeat (preferable dozens or even hundreds of times)

Comment 4 Preethi Thomas 2011-12-22 13:47:39 UTC
verified
[root@pulpf15-client ~]# rpm -q pulp-consumer
pulp-consumer-0.0.255-1.fc15.noarch

I have tried the consumer register /unregister over 100 times without getting the error.

Comment 5 Preethi Thomas 2012-02-24 20:13:43 UTC
Pulp v1.0 is released
Closed Current Release.