From b5f7cf989c6f233fb2b0dd759cc33afb94761ec2 Mon Sep 17 00:00:00 2001 From: Chris Buccella Date: Wed, 26 Mar 2014 19:48:16 +0000 Subject: [PATCH] Import request_id middleware bug fix from oslo There is a bug in request-id middleware that a subsequent API request will overwrite a request-id of a previous request when multiple API calls are processed in parallel in request_id middleware. The fix is a drop-in replacement; cinder code does not need to be modified to use the updated request_id middleware. oslo change to fix the middleware: d7bd9dc37ac3d6bc171cd2e290c772633ad20a32 Closes-Bug: #1289696 Change-Id: Ib211318c47681f841bcde04e490ccc2070bdf8de --- cinder/openstack/common/middleware/request_id.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cinder/openstack/common/middleware/request_id.py b/cinder/openstack/common/middleware/request_id.py index 53d9813b0..e7e415776 100644 --- a/cinder/openstack/common/middleware/request_id.py +++ b/cinder/openstack/common/middleware/request_id.py @@ -19,6 +19,8 @@ It ensures to assign request ID for each API request and set it to request environment. The request ID is also added to API response. """ +import webob.dec + from cinder.openstack.common import context from cinder.openstack.common.middleware import base @@ -29,10 +31,11 @@ HTTP_RESP_HEADER_REQUEST_ID = 'x-openstack-request-id' class RequestIdMiddleware(base.Middleware): - def process_request(self, req): - self.req_id = context.generate_request_id() - req.environ[ENV_REQUEST_ID] = self.req_id - - def process_response(self, response): - response.headers.add(HTTP_RESP_HEADER_REQUEST_ID, self.req_id) + @webob.dec.wsgify + def __call__(self, req): + req_id = context.generate_request_id() + req.environ[ENV_REQUEST_ID] = req_id + response = req.get_response(self.application) + if HTTP_RESP_HEADER_REQUEST_ID not in response.headers: + response.headers.add(HTTP_RESP_HEADER_REQUEST_ID, req_id) return response -- 2.45.2