Skip to content

Commit b46a03c

Browse files
imsahil007pdxjohnny
authored andcommitted
limiting tcp connections to nvd (#1093)
1 parent a1f534e commit b46a03c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

cve_bin_tool/cvedb.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
DISK_LOCATION_DEFAULT = os.path.join(os.path.expanduser("~"), ".cache", "cve-bin-tool")
3636
DBNAME = "cve.db"
3737
OLD_CACHE_DIR = os.path.join(os.path.expanduser("~"), ".cache", "cvedb")
38-
# Workaround for issue #1081
39-
RATE_LIMITER = asyncio.BoundedSemaphore(2)
4038

4139

4240
class CVEDB:
@@ -132,9 +130,9 @@ async def cache_update(self, session, url, sha, chunk_size=16 * 1024):
132130
self.LOGGER.debug(f"Correct SHA for {filename}")
133131
return
134132
self.LOGGER.debug(f"Updating CVE cache for {filename}")
135-
async with RATE_LIMITER:
136-
async with session.get(url) as response:
137-
gzip_data = await response.read()
133+
134+
async with session.get(url) as response:
135+
gzip_data = await response.read()
138136
json_data = gzip.decompress(gzip_data)
139137
gotsha = hashlib.sha256(json_data).hexdigest().upper()
140138
async with FileIO(filepath, "wb") as filepath_handle:
@@ -193,7 +191,8 @@ async def refresh(self):
193191
self.LOGGER.info("Checking if there is a newer version.")
194192
check_latest_version()
195193
if not self.session:
196-
self.session = aiohttp.ClientSession(trust_env=True)
194+
connector = aiohttp.TCPConnector(limit_per_host=19)
195+
self.session = aiohttp.ClientSession(connector=connector, trust_env=True)
197196
self.LOGGER.info("Downloading CVE data...")
198197
nvd_metadata, curl_metadata = await asyncio.gather(
199198
self.nist_scrape(self.session), self.get_curl_versions(self.session)

test/test_cvedb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def teardown_class(cls):
2222

2323
@pytest.mark.asyncio
2424
async def test_00_getmeta(self):
25-
async with aiohttp.ClientSession(trust_env=True) as session:
25+
connector = aiohttp.TCPConnector(limit_per_host=19)
26+
async with aiohttp.ClientSession(
27+
connector=connector, trust_env=True
28+
) as session:
2629
_jsonurl, meta = await self.cvedb.getmeta(
2730
session,
2831
"https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-modified.meta",

0 commit comments

Comments
 (0)