From 4a1c60fba2c088e25bb0ebb6e2de6d3f57825fc9 Mon Sep 17 00:00:00 2001 From: Martin Bornhold Date: Wed, 22 Jun 2016 10:18:06 +0200 Subject: [PATCH] threading: Add factory that creates curl session for each thread. When creating a repo with an import url pointing to another repo on the same enterprise instance we call the vcssserver to check the url. The vcsserver then calls to enterprise to verify the url. This leads to two threads using the same cur session. --- rhodecode/lib/vcs/client_http.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rhodecode/lib/vcs/client_http.py b/rhodecode/lib/vcs/client_http.py index c2721e0c..42b882b3 100644 --- a/rhodecode/lib/vcs/client_http.py +++ b/rhodecode/lib/vcs/client_http.py @@ -31,6 +31,7 @@ implementation. import copy import logging +import threading import urllib2 import urlparse import uuid @@ -38,7 +39,7 @@ import uuid import msgpack import requests -from . import exceptions +from . import exceptions, CurlSession log = logging.getLogger(__name__) @@ -216,3 +217,17 @@ class VcsHttpProxy(object): headers = iterator.next() return iterator, status, headers + + +class ThreadlocalSessionFactory(object): + """ + Creates one CurlSession per thread on demand. + """ + + def __init__(self): + self._thread_local = threading.local() + + def __call__(self): + if not hasattr(self._thread_local, 'curl_session'): + self._thread_local.curl_session = CurlSession() + return self._thread_local.curl_session