Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions coco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,17 @@ def __init__(self, conf, reset=False, check_config=False):
raise ConfigError(
f"Failed parsing value 'timeout' ({self.config['timeout']})."
) from e
try:
dns_cache_ttl = str2total_seconds(self.config["dns_cache_ttl"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one should probably have a default value rather than throwing a ConfigError if it's missing.

except Exception as e:
raise ConfigError(
f"Failed parsing value 'dns_cache_ttl' ({self.config['dns_cache_ttl']})."
) from e
self.forwarder = RequestForwarder(
self.blocklist_path,
timeout,
debug_connections=self.config["debug_connections"],
dns_cache_ttl=dns_cache_ttl
)
self.forwarder.set_session_limit(self.config["session_limit"])
for group, hosts in self.groups.items():
Expand Down
6 changes: 3 additions & 3 deletions coco/request_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class RequestForwarder:
"""

def __init__(
self, blocklist_path: os.PathLike, timeout: int, debug_connections: bool = False
self, blocklist_path: os.PathLike, timeout: int, debug_connections: bool = False, dns_cache_ttl: int = 10
):
self._endpoints = dict()
self._groups = dict()
Expand All @@ -210,6 +210,7 @@ def __init__(
self.queue_wait_time = None
self.response_time = None
self._debug_connections = debug_connections
self._connector = aiohttp.TCPConnector(limit=0, ttl_dns_cache=dns_cache_ttl)

def set_session_limit(self, session_limit):
"""
Expand Down Expand Up @@ -421,9 +422,8 @@ async def external(self, name, request, hosts, method, params=None, timeout=None
if timeout is None:
timeout = self.timeout

connector = aiohttp.TCPConnector(limit=0)
async with aiohttp.ClientSession(
connector=connector,
connector=self._connector,
trace_configs=([_trace_config()] if self._debug_connections else None),
) as session, TaskPool(self.session_limit) as tasks:
for host in hosts:
Expand Down
1 change: 1 addition & 0 deletions coco/test/coco_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"host": "localhost",
"port": 12055,
"log_level": "DEBUG",
"dns_cache_ttl": 60,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might use a string like 60s or 1m to exercise the parsing logic.

"blocklist_path": str(BLOCKLIST_PATH),
"storage_path": STATE_DIR.name,
}
Expand Down