|
5 | 5 | from __future__ import division
|
6 | 6 |
|
7 | 7 | import os
|
| 8 | +import time |
8 | 9 | import six
|
9 | 10 | import tempfile
|
10 | 11 |
|
|
29 | 30 | urls = os.environ['DEBUGINFOD_URLS'].split(' ')
|
30 | 31 | DEBUGINFOD_SERVERS = urls + DEBUGINFOD_SERVERS
|
31 | 32 |
|
| 33 | +# Retry failed lookups after some time |
| 34 | +NEGATIVE_CACHE_EXPIRY = 60 * 60 * 24 * 7 # 1 week |
| 35 | + |
32 | 36 | # https://gitlab.com/libcdb/libcdb wasn't updated after 2019,
|
33 | 37 | # but still is a massive database of older libc binaries.
|
34 | 38 | def provider_libcdb(hex_encoded_id, hash_type):
|
@@ -109,6 +113,10 @@ def search_by_hash(hex_encoded_id, hash_type='build_id', unstrip=True):
|
109 | 113 | cache, cache_valid = _check_elf_cache('libcdb', hex_encoded_id, hash_type)
|
110 | 114 | if cache_valid:
|
111 | 115 | return cache
|
| 116 | + |
| 117 | + # We searched for this buildid before, but didn't find anything. |
| 118 | + if cache is None: |
| 119 | + return None |
112 | 120 |
|
113 | 121 | # Run through all available libc database providers to see if we have a match.
|
114 | 122 | for provider in PROVIDERS:
|
@@ -141,6 +149,10 @@ def _search_debuginfo_by_hash(base_url, hex_encoded_id):
|
141 | 149 | cache, cache_valid = _check_elf_cache('libcdb_dbg', hex_encoded_id, 'build_id')
|
142 | 150 | if cache_valid:
|
143 | 151 | return cache
|
| 152 | + |
| 153 | + # We searched for this buildid before, but didn't find anything. |
| 154 | + if cache is None: |
| 155 | + return None |
144 | 156 |
|
145 | 157 | # Try to find separate debuginfo.
|
146 | 158 | url = '/buildid/{}/debuginfo'.format(hex_encoded_id)
|
@@ -191,8 +203,11 @@ def _check_elf_cache(cache_type, hex_encoded_id, hash_type):
|
191 | 203 |
|
192 | 204 | data = read(cache)
|
193 | 205 | if not data.startswith(b'\x7FELF'):
|
194 |
| - log.info_once("Skipping unavailable ELF %s", hex_encoded_id) |
195 |
| - return cache, False |
| 206 | + # Retry failed lookups after some time |
| 207 | + if time.time() > os.path.getmtime(cache) + NEGATIVE_CACHE_EXPIRY: |
| 208 | + return cache, False |
| 209 | + log.info_once("Skipping invalid cached ELF %s", hex_encoded_id) |
| 210 | + return None, False |
196 | 211 |
|
197 | 212 | log.info_once("Using cached data from %r", cache)
|
198 | 213 | return cache, True
|
|
0 commit comments