Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: add connect timeout for exec websockets to avoid hanging #1247

Merged
merged 3 commits into from
Jun 6, 2024
Merged
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 ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -2832,10 +2832,17 @@ def _cancel_stdin():

def _connect_websocket(self, task_id: str, websocket_id: str) -> '_WebSocket':
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Set socket timeout to a short timeout during connection phase, in
# case the Pebble side times out (5s), so this side doesn't hang. See:
# https://github.com/canonical/operator/issues/1246
sock.settimeout(self.timeout)
sock.connect(self.socket_path)
url = self._websocket_url(task_id, websocket_id)
ws: _WebSocket = websocket.WebSocket(skip_utf8_validation=True) # type: ignore
ws.connect(url, socket=sock)
# Reset to no timeout so connection can be "long polling" when data is
# being received.
sock.settimeout(None)
return ws

def _websocket_url(self, task_id: str, websocket_id: str) -> str:
Expand Down
Loading