Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Run oscrypto_check_hostname in a ThreadPoolExecutor
Browse files Browse the repository at this point in the history
because oscrpyto doesn't provide async APIs. See:
wbond/oscrypto#1

The two solutions to the blocking problem is:
- completely remove oscrypto support and only call Python's build in
  non-blocking APIs
- run oscrypto calls in a ThreadPoolExecutor
  • Loading branch information
kissgyorgy committed Oct 30, 2018
1 parent e3fb401 commit 9ad2685
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions certmaestro/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ def oscrypto_check_hostname(hostname):


class CheckSiteManager:
def __init__(self, redirect, timeout, retries):
def __init__(self, redirect, timeout, retries, *, loop=None):
self.redirect = redirect
self.timeout = timeout
self.retries = retries
self.skipped = []
self.succeeded = []
self.failed = []

executor = futures.ThreadPoolExecutor(max_workers=10)
self.loop = loop or asyncio.get_event_loop()
self.loop.set_default_executor(executor)

@property
def success_count(self):
return len(self.succeeded)
Expand Down Expand Up @@ -124,7 +128,7 @@ async def _check_hostname(self, hostname):
return CheckedSite(hostname, CheckResult.FAILED, openssl_error)
else:
# OSCrypto gives better error messages, but it is less strict
oscrypto_error = oscrypto_check_hostname(hostname)
oscrypto_error = await self.loop.run_in_executor(None, oscrypto_check_hostname, hostname)
error_message = oscrypto_error or openssl_error
return CheckedSite(hostname, CheckResult.FAILED, error_message)

Expand Down
2 changes: 1 addition & 1 deletion certmaestro/cli/groups/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def check(ctx, urls, timeout, retries, redirect):

click.echo('Checking certificates...')

manager = CheckSiteManager(redirect, timeout, retries)
loop = asyncio.get_event_loop()
manager = CheckSiteManager(redirect, timeout, retries, loop=loop)
loop.run_until_complete(_check_sites(manager, urls))

total_message = click.style(f'Total: {len(urls)}', fg='blue')
Expand Down

0 comments on commit 9ad2685

Please sign in to comment.