Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 68f97b3

Browse files
committed
Merge pull request #416 from dotcloud/272-dont-die-on-redis-errors
Don't crash on Redis connection errors
2 parents 08bac44 + a44ca41 commit 68f97b3

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

depends/docker-registry-core/docker_registry/core/lru.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def wrapper(*args):
6565
content = args[-1]
6666
key = args[-2]
6767
key = cache_key(key)
68-
redis_conn.set(key, content)
68+
try:
69+
redis_conn.set(key, content)
70+
except redis.exceptions.ConnectionError as e:
71+
logging.warning("LRU: Redis connection error: {0}".format(e))
72+
6973
return f(*args)
7074
if redis_conn is None:
7175
return f
@@ -77,13 +81,21 @@ def get(f):
7781
def wrapper(*args):
7882
key = args[-1]
7983
key = cache_key(key)
80-
content = redis_conn.get(key)
84+
try:
85+
content = redis_conn.get(key)
86+
except redis.exceptions.ConnectionError as e:
87+
logging.warning("LRU: Redis connection error: {0}".format(e))
88+
content = None
89+
8190
if content is not None:
8291
return content
8392
# Refresh cache
8493
content = f(*args)
8594
if content is not None:
86-
redis_conn.set(key, content)
95+
try:
96+
redis_conn.set(key, content)
97+
except redis.exceptions.ConnectionError as e:
98+
logging.warning("LRU: Redis connection error: {0}".format(e))
8799
return content
88100
if redis_conn is None:
89101
return f
@@ -95,7 +107,10 @@ def remove(f):
95107
def wrapper(*args):
96108
key = args[-1]
97109
key = cache_key(key)
98-
redis_conn.delete(key)
110+
try:
111+
redis_conn.delete(key)
112+
except redis.exceptions.ConnectionError as e:
113+
logging.warning("LRU: Redis connection error: {0}".format(e))
99114
return f(*args)
100115
if redis_conn is None:
101116
return f

docker_registry/images.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ def put_image_checksum(image_id):
289289
# Checksum is ok, we remove the marker
290290
store.remove(mark_path)
291291
# We trigger a task on the diff worker if it's running
292-
if cache.redis_conn:
293-
layers.diff_queue.push(image_id)
292+
layers.enqueue_diff(image_id)
294293
return toolkit.response()
295294

296295

docker_registry/lib/layers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import logging
34
import tarfile
45
import tempfile
56

@@ -28,10 +29,20 @@
2829
tarfile.GNUTYPE_SPARSE: 'S',
2930
}
3031

32+
logger = logging.getLogger(__name__)
33+
3134
# queue for requesting diff calculations from workers
3235
diff_queue = rqueue.CappedCollection(cache.redis_conn, "diff-worker", 1024)
3336

3437

38+
def enqueue_diff(image_id):
39+
try:
40+
if cache.redis_conn:
41+
diff_queue.push(image_id)
42+
except cache.redis.exceptions.ConnectionError as e:
43+
logger.warning("Diff queue: Redis connection error: {0}".format(e))
44+
45+
3546
def generate_ancestry(image_id, parent_id=None):
3647
if not parent_id:
3748
store.put_content(store.image_ancestry_path(image_id),

docker_registry/lib/mirroring.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,16 @@ def wrapper(namespace, repository, *args, **kwargs):
105105
# client GETs a single tag
106106
tag_path = store.tag_path(namespace, repository, kwargs['tag'])
107107

108-
data = cache.redis_conn.get('{0}:{1}'.format(
109-
cache.cache_prefix, tag_path
110-
))
108+
try:
109+
data = cache.redis_conn.get('{0}:{1}'.format(
110+
cache.cache_prefix, tag_path
111+
))
112+
except cache.redis.exceptions.ConnectionError as e:
113+
data = None
114+
logger.warning("Diff queue: Redis connection error: {0}".format(
115+
e
116+
))
117+
111118
if data is not None:
112119
return toolkit.response(data=data, raw=True)
113120
source_resp = lookup_source(
@@ -117,9 +124,15 @@ def wrapper(namespace, repository, *args, **kwargs):
117124
return resp
118125
data = source_resp.content
119126
headers = _response_headers(source_resp.headers)
120-
cache.redis_conn.setex('{0}:{1}'.format(
121-
cache.cache_prefix, tag_path
122-
), tags_cache_ttl, data)
127+
try:
128+
cache.redis_conn.setex('{0}:{1}'.format(
129+
cache.cache_prefix, tag_path
130+
), tags_cache_ttl, data)
131+
except cache.redis.exceptions.ConnectionError as e:
132+
logger.warning("Diff queue: Redis connection error: {0}".format(
133+
e
134+
))
135+
123136
return toolkit.response(data=data, headers=headers,
124137
raw=True)
125138
return wrapper

0 commit comments

Comments
 (0)