Skip to content

Commit

Permalink
add timeout, so query does not hang case server is unreachable (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomach authored Aug 26, 2024
1 parent 3050548 commit 94fcb35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/charms/mysql/v0/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def wait_until_mysql_connection(self) -> None:
# Increment this major API version when introducing breaking changes
LIBAPI = 0

LIBPATCH = 69
LIBPATCH = 70

UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
UNIT_ADD_LOCKNAME = "unit-add"
Expand Down Expand Up @@ -1536,7 +1536,9 @@ def cluster_metadata_exists(self, from_instance: str) -> bool:
)

try:
output = self._run_mysqlsh_script("\n".join(check_cluster_metadata_commands))
output = self._run_mysqlsh_script(
"\n".join(check_cluster_metadata_commands), timeout=10
)
except MySQLClientError:
logger.warning(f"Failed to check if cluster metadata exists {from_instance=}")
return False
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def test_cluster_metadata_exists(self, _run_mysqlsh_script):
_run_mysqlsh_script.return_value = "True\n"

self.assertTrue(self.mysql.cluster_metadata_exists("1.2.3.4"))
_run_mysqlsh_script.assert_called_once_with(commands)
_run_mysqlsh_script.assert_called_once_with(commands, timeout=10)

_run_mysqlsh_script.reset_mock()
_run_mysqlsh_script.side_effect = MySQLClientError
Expand Down

0 comments on commit 94fcb35

Please sign in to comment.