From 738e67c90c6abfdf5030f894c7ef8950ee42c8ae Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Tue, 20 Oct 2015 01:59:51 +0000 Subject: [PATCH] mirrorlist: Use a thread-local copy of the tree to prevent changing the global one This makes sure that the global version does not get changed while processing a request, keeping the hostnet check working across requests. Signed-off-by: Patrick Uiterwijk --- files/hotfix/mirrorlist/mirrorlist_server.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/files/hotfix/mirrorlist/mirrorlist_server.py b/files/hotfix/mirrorlist/mirrorlist_server.py index 39dfc7a786..b8842295ac 100755 --- a/files/hotfix/mirrorlist/mirrorlist_server.py +++ b/files/hotfix/mirrorlist/mirrorlist_server.py @@ -6,6 +6,7 @@ # standard library modules in alphabetical order from collections import defaultdict +import copy import datetime import getopt import logging @@ -234,11 +235,12 @@ def tree_lookup(tree, ip, field, maxResults=None): # and we'll get a new copy of the tree from our parent the next time it # fork()s. # returns a list of tuples (prefix, data) + ltree = copy.deepcopy(tree) result = [] len_data = 0 if ip is None: return result - node = tree.search_best(ip.strNormal()) + node = ltree.search_best(ip.strNormal()) while node is not None: prefix = node.prefix if type(node.data[field]) == list: @@ -248,8 +250,8 @@ def tree_lookup(tree, ip, field, maxResults=None): t = (prefix, node.data[field],) result.append(t) if maxResults is None or len_data < maxResults: - tree.delete(prefix) - node = tree.search_best(ip.strNormal()) + ltree.delete(prefix) + node = ltree.search_best(ip.strNormal()) else: break return result