-
Notifications
You must be signed in to change notification settings - Fork 75
Ssh Test and Debugging Fixups #1015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0678f96
a3a82f7
fcbfc49
c666915
2dcfa42
9965602
57b673a
2084a08
ecebe33
e7f524d
1b490ae
9ad7794
3c0aa23
a8d9ccd
1862037
b2530a3
d914bcc
b6b5561
b059ac3
021f451
ac57951
4462cdf
74d94cf
06a9826
cba92cd
797ac40
07924d6
9870d35
c775d89
72aec7b
9fd6843
95a4ae0
6fbd25b
382ab78
496fba8
6298fa4
2f7c010
06d4d8d
3621506
751028e
d4fc3ba
5ef8132
74c30f8
4b090c6
fd61c79
5b28210
2c8668f
5088cae
f1ca2d0
bee6f99
d6107ad
ba46ff6
30f87f1
30b7d6a
a4be9fb
13efd80
1ec818c
ecb7c96
dc9d51a
633bf41
8718d65
f44a4ee
d405bfb
6d7d3f7
e6af465
8334ede
4458b57
5a79292
59893d7
991d504
ca59432
5904817
74fa084
421e2c5
0f52e5f
5ddff64
a59c2a8
804bb91
ff31b4e
dae49cd
4b981f8
fcd2266
3d5da84
95f7bc5
586472f
8e2af72
938d53f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,3 +171,6 @@ build/*.build-stamp | |
| *.duckdb | ||
| *.db.wal | ||
| *.duckdb.wal | ||
|
|
||
| # pytest logs | ||
| logs/pytest*.log | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| from abc import ABCMeta | ||
| from asyncio import Event as CoroEvent | ||
| from asyncio import Lock as CoroLock | ||
| from asyncio import sleep as async_sleep | ||
| from collections.abc import Callable, Coroutine | ||
| from threading import current_thread | ||
| from types import TracebackType | ||
|
|
@@ -172,34 +173,60 @@ async def get_client_connection( | |
| A tuple of (SSHClientConnection, SshClient). | ||
| """ | ||
| _LOG.debug("%s: get_client_connection: %s", current_thread().name, connect_params) | ||
| async with self._cache_lock: | ||
| connection_id = SshClient.id_from_params(connect_params) | ||
| client: None | SshClient | asyncssh.SSHClient | ||
| _, client = self._cache.get(connection_id, (None, None)) | ||
| if client: | ||
| _LOG.debug("%s: Checking cached client %s", current_thread().name, connection_id) | ||
| connection = await client.connection() | ||
| if not connection: | ||
| _LOG.debug( | ||
| "%s: Removing stale client connection %s from cache.", | ||
| current_thread().name, | ||
| connection_id, | ||
| ) | ||
| self._cache.pop(connection_id) | ||
| # Try to reconnect next. | ||
| else: | ||
| _LOG.debug("%s: Using cached client %s", current_thread().name, connection_id) | ||
| if connection_id not in self._cache: | ||
| _LOG.debug( | ||
| "%s: Establishing client connection to %s", | ||
| connection_id = SshClient.id_from_params(connect_params) | ||
| for i in range(3): # TODO: make the retry count configurable | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. polish
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and add tests
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and config support |
||
| try: | ||
| async with self._cache_lock: | ||
| client: None | SshClient | asyncssh.SSHClient | ||
| _, client = self._cache.get(connection_id, (None, None)) | ||
| if client: | ||
| _LOG.debug( | ||
| "%s: Checking cached client %s", current_thread().name, connection_id | ||
| ) | ||
| connection = await client.connection() | ||
| if not connection: | ||
| _LOG.debug( | ||
| "%s: Removing stale client connection %s from cache.", | ||
| current_thread().name, | ||
| connection_id, | ||
| ) | ||
| self._cache.pop(connection_id) | ||
| # Try to reconnect next. | ||
| else: | ||
| _LOG.debug( | ||
| "%s: Using cached client %s", current_thread().name, connection_id | ||
| ) | ||
| if connection_id not in self._cache: | ||
| _LOG.debug( | ||
| "%s: Establishing client connection to %s", | ||
| current_thread().name, | ||
| connection_id, | ||
| ) | ||
| connection, client = await asyncssh.create_connection( | ||
| SshClient, **connect_params | ||
| ) | ||
| assert isinstance(client, SshClient) | ||
| self._cache[connection_id] = (connection, client) | ||
| _LOG.debug( | ||
| "%s: Created connection to %s.", current_thread().name, connection_id | ||
| ) | ||
| return self._cache[connection_id] | ||
| except ConnectionRefusedError as ex: # TODO: Add other error handling here too | ||
| _LOG.warning( | ||
| "%s: Attempt %d: Failed to connect to %s: %s", | ||
| current_thread().name, | ||
| i + 1, | ||
| connection_id, | ||
| ex, | ||
| ) | ||
| connection, client = await asyncssh.create_connection(SshClient, **connect_params) | ||
| assert isinstance(client, SshClient) | ||
| self._cache[connection_id] = (connection, client) | ||
| _LOG.debug("%s: Created connection to %s.", current_thread().name, connection_id) | ||
| return self._cache[connection_id] | ||
| if i < 2: # TODO: adjust to match max range | ||
| await async_sleep(1.0) # TODO: Make this configurable | ||
| if i == 2: # TODO: adjust to match max range | ||
| _LOG.error( | ||
| "%s: Giving up connecting to %s", current_thread().name, connection_id | ||
| ) | ||
| raise | ||
| raise RuntimeError("Unreachable code in get_client_connection") | ||
|
|
||
| def cleanup(self) -> None: | ||
| """Closes all cached connections.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixme - only apply to console logger for pytest