TypeError: an integer is required

Bug #1213106 reported by JPascal
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
High
Jamie Lennox
oslo.middleware
Fix Released
Undecided
Brant Knudson

Bug Description

2013-08-16 13:20:10 ERROR [keystone.common.wsgi] an integer is required
Traceback (most recent call last):
  File "/opt/keystone/keystone/common/wsgi.py", line 372, in __call__
    response = self.process_request(request)
  File "/opt/keystone/keystone/middleware/core.py", line 111, in process_request
    params_json = request.body
  File "/usr/lib/python2.7/dist-packages/webob/request.py", line 677, in _body__get
    self.make_body_seekable() # we need this to have content_length
  File "/usr/lib/python2.7/dist-packages/webob/request.py", line 922, in make_body_seekable
    self.copy_body()
  File "/usr/lib/python2.7/dist-packages/webob/request.py", line 938, in copy_body
    self.body = self.body_file_raw.read()
  File "/opt/keystone/keystone/common/utils.py", line 261, in read
    result = self.data.read(i)
TypeError: an integer is required

Revision history for this message
Wu Wenxiang (wu-wenxiang) wrote :

Could you give more information about this issue?
For example:
1. Which operation trigger this issue?
2. How to reproduce?
3. Which version?

Changed in keystone:
assignee: nobody → Wu Wenxiang (wu-wenxiang)
Revision history for this message
JPascal (eshurmin) wrote :

Version:
https://github.com/openstack/keystone/tree/2013.2.b2

Reproduce:
# request
curl -H "Content-type: application/json" -H "X-Auth-Token:$token" -d '{"tenant":{"enabled":true, "name":"admin"}}' http://localhost:35357/v2.0/tenants
# response
{"tenants_links": [], "tenants": [{"description": "", "enabled": true, "id": "abc0a6f227c740859f0fd3410ef310e9", "name": "admin"}]}

# request
curl -H "Content-type: application/json" -H "X-Auth-Token:$token" -d '{"user":{"tenant_id":"abc0a6f227c740859f0fd3410ef310e9", "password":"crowbar", "enabled":true, "name":"admin"}}' http://localhost:35357/v2.0/users
#response
{"user": {"name": "admin", "tenant_id": "abc0a6f227c740859f0fd3410ef310e9", "enabled": true, "id": "4ab39dacc7f849cebe789b640b788054"}}

#request
curl -H "Content-type: application/json" -H "X-Auth-Token:$token" -d '{"role":{"name":"admin"}}' http://localhost:35357/v2.0/OS-KSADM/roles
#response
{"role": {"id": "f10e95604b994df28bcada736afdae82", "name": "admin"}}

#request
curl -X PUT -H "Content-type: application/json" -H "X-Auth-Token:$token" http://localhost:35357/v2.0/tenants/$tenant_id/users/$user_id/roles/OS-KSADM/$role_id
#response
{"error": {"message": "an integer is required", "code": 400, "title": "Bad Request"}}

If I change https://github.com/openstack/keystone/blob/2013.2.b2/keystone/common/utils.py#L260 to
"def read(self, i=0):" this work correctly.

Revision history for this message
Dolph Mathews (dolph) wrote :

I'm not able to reproduce this. If this is still reproducible, please comment!

Changed in keystone:
status: New → Invalid
Revision history for this message
JPascal (eshurmin) wrote :

Hello. Long time can't look again on this bug.
Bug still exists in repo with tag 2013.2.b2

Revision history for this message
JPascal (eshurmin) wrote :

Also addition information.
If I run keystone as native, all work correctly, if I run using apache it bug exists.

Revision history for this message
Dolph Mathews (dolph) wrote :

Re-opening based on the above; I didn't test this behind apache.

Changed in keystone:
status: Invalid → New
importance: Undecided → High
Revision history for this message
Brant Knudson (blk-u) wrote :

Looking at current keystone/common/utils.py, https://github.com/openstack/keystone/blob/master/keystone/common/utils.py#L261, line 268 is not a read()... there's a read at line 293. Why would it be so far off?

Revision history for this message
Dolph Mathews (dolph) wrote :
Revision history for this message
xingzhou (xingzhou) wrote : Zhou Z Xing is out of the office.

I will be out of the office starting 2013/10/01 and will not return until
2013/10/07.

I will check mails at night and try to respond you ASAP

Revision history for this message
JPascal (eshurmin) wrote : Re: [Bug 1213106] Re: TypeError: an integer is required

I work with git usung tag 2013.2.b2, not master branch.
Looking at current keystone/common/utils.py,
https://github.com/openstack/keystone/blob/master/keystone/common/utils.py#L261
,
line 268 is not a read()... there's a read at line 293. Why would it be
so far off?

--
You received this bug notification because you are subscribed to the bug
report.
https://bugs.launchpad.net/bugs/1213106

Title:
  TypeError: an integer is required

Status in OpenStack Identity (Keystone):
  New

Bug description:
  2013-08-16 13:20:10 ERROR [keystone.common.wsgi] an integer is required
  Traceback (most recent call last):
    File "/opt/keystone/keystone/common/wsgi.py", line 372, in __call__
      response = self.process_request(request)
    File "/opt/keystone/keystone/middleware/core.py", line 111, in
process_request
      params_json = request.body
    File "/usr/lib/python2.7/dist-packages/webob/request.py", line 677, in
_body__get
      self.make_body_seekable() # we need this to have content_length
    File "/usr/lib/python2.7/dist-packages/webob/request.py", line 922, in
make_body_seekable
      self.copy_body()
    File "/usr/lib/python2.7/dist-packages/webob/request.py", line 938, in
copy_body
      self.body = self.body_file_raw.read()
    File "/opt/keystone/keystone/common/utils.py", line 261, in read
      result = self.data.read(i)
  TypeError: an integer is required

To manage notifications about this bug go to:
https://bugs.launchpad.net/keystone/+bug/1213106/+subscriptions

Revision history for this message
Jamie Lennox (jamielennox) wrote :

Confirmed behind apache in master - investingating

Changed in keystone:
status: New → Confirmed
Revision history for this message
Jamie Lennox (jamielennox) wrote :

Firstly this is being caused because when you issue the curl command for a PUT method without a data object it does not set a Content-Length header. If you are working with older keystones you can fix this by including a -H "Content-Length: 0" statement to your command line.

What appears to be happening is that the eventlet and mod_wsgi implementations of wsgi.Input differ. The wsgi PEP http://www.python.org/dev/peps/pep-0333 specifies you must be able to read and that you it takes an optional limit argument but it does not specify the expected default value for the limit if not provided.

None, the value we have been using works as a default for eventlet. I can't find actual documentation but -1 appears to do the same thing for mod_wsgi, but passing the wrong default value leads to this failure and something similar in eventlet.

The fix should be fairly simple, just check if a limit value was provided and only provide the optional argument to the real read if provided.

Changed in keystone:
assignee: Wu Wenxiang (wu-wenxiang) → Jamie Lennox (jamielennox)
Revision history for this message
Dolph Mathews (dolph) wrote :

Great analysis!

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (master)

Fix proposed to branch: master
Review: https://review.openstack.org/50524

Changed in keystone:
status: Confirmed → In Progress
Dolph Mathews (dolph)
tags: added: havana-backport-potential
Revision history for this message
Thierry Carrez (ttx) wrote :

Looks like a corner case to me, so downgrading prio

tags: added: havana-rc-potential
removed: havana-backport-potential
Changed in keystone:
importance: High → Medium
Revision history for this message
Thierry Carrez (ttx) wrote :

That corner case is the advertised way of doing it, so back to High, and RC2-blocking

Changed in keystone:
importance: Medium → High
milestone: none → havana-rc2
tags: removed: havana-rc-potential
Dolph Mathews (dolph)
tags: added: havana-rc-potential
tags: removed: havana-rc-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (milestone-proposed)

Fix proposed to branch: milestone-proposed
Review: https://review.openstack.org/50664

Revision history for this message
Dolph Mathews (dolph) wrote :

backport to milestone-proposed: https://review.openstack.org/#/c/50664/

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (master)

Reviewed: https://review.openstack.org/50524
Committed: http://github.com/openstack/keystone/commit/12fd2aa50096b77c044ca8840657de5f2c16513e
Submitter: Jenkins
Branch: master

commit 12fd2aa50096b77c044ca8840657de5f2c16513e
Author: Jamie Lennox <email address hidden>
Date: Wed Oct 9 11:49:58 2013 +1000

    Don't use default value in LimitingReader

    We can't simply pass the None default on to the read operation as this
    default is handled differently between different wsgi implementations.

    Change-Id: I337e797b8dee3dfcf9299fe361cf197a176c8fe2
    Fixes: bug 1213106

Changed in keystone:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (milestone-proposed)

Reviewed: https://review.openstack.org/50664
Committed: http://github.com/openstack/keystone/commit/c14ebd668f00b1d0c0f3c94fa331b2080d5ec053
Submitter: Jenkins
Branch: milestone-proposed

commit c14ebd668f00b1d0c0f3c94fa331b2080d5ec053
Author: Jamie Lennox <email address hidden>
Date: Wed Oct 9 11:49:58 2013 +1000

    Don't use default value in LimitingReader

    We can't simply pass the None default on to the read operation as this
    default is handled differently between different wsgi implementations.

    Change-Id: I337e797b8dee3dfcf9299fe361cf197a176c8fe2
    Fixes: bug 1213106

Changed in keystone:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in keystone:
milestone: havana-rc2 → 2013.2
Revision history for this message
Brant Knudson (blk-u) wrote :

The old code without the fix is in oslo.middleware . Ran into this when trying to change Keystone to use oslo.middleware: http://logs.openstack.org/97/144697/1/check/check-tempest-dsvm-full/4a13e44/logs/apache/keystone.txt.gz#_2015-01-01_23_57_43_514 for https://review.openstack.org/#/c/144697/

I ported the fix to oslo.middleware: https://review.openstack.org/#/c/144700/

Changed in oslo.middleware:
assignee: nobody → Brant Knudson (blk-u)
status: New → In Progress
Revision history for this message
Doug Hellmann (doug-hellmann) wrote :

This was fixed in 7c8e3e1061c2b51be59f034e0cd5b914a4ad6f47 and released in 0.3.0

Changed in oslo.middleware:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.