Skip to content

Commit

Permalink
Increase default SnapClient timeout to 30 seconds (#111)
Browse files Browse the repository at this point in the history
* Increase default SnapClient timeout to 30 seconds

SnapClient has a default timeout of 5 seconds for all RPCs to
the snapd socket. If any operation takes more, an exception is
raised to the caller.

We have seen this causing issues in slow CI environments, where
a simple config-changed hook will attempt to check if a snap is
installed, timeout and move the unit to a blocked status (causing
the CI run to fail). This is augmented by the fact that typically
SnapCache is used instead of SnapClient, which only uses the default
value and does not provide a way to configure the timeout.

Simply increasing the timeout is enough to tackle the flakes.

* Bump LIBPATCH to 3
  • Loading branch information
neoaggelos authored Sep 14, 2023
1 parent 20b8afd commit ad65cde
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/charms/operator_libs_linux/v2/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 2
LIBPATCH = 3


# Regex to locate 7-bit C1 ANSI sequences
Expand Down Expand Up @@ -692,7 +692,7 @@ def __init__(
socket_path: str = "/run/snapd.socket",
opener: Optional[urllib.request.OpenerDirector] = None,
base_url: str = "http://localhost/v2/",
timeout: float = 5.0,
timeout: float = 30.0,
):
"""Initialize a client instance.
Expand All @@ -701,7 +701,7 @@ def __init__(
opener: specifies an opener for unix socket, if unspecified a default is used
base_url: base url for making requests to the snap client. Defaults to
http://localhost/v2/
timeout: timeout in seconds to use when making requests to the API. Default is 5.0s.
timeout: timeout in seconds to use when making requests to the API. Default is 30.0s.
"""
if opener is None:
opener = self._get_default_opener(socket_path)
Expand Down

0 comments on commit ad65cde

Please sign in to comment.