|
21 | 21 | from ..collections import EMPTY_DICT |
22 | 22 | from ..exceptions import DCSError, PatroniException |
23 | 23 | from ..postgresql.mpp import AbstractMPP |
24 | | -from ..utils import deep_compare, enable_keepalive, iter_response_objects, RetryFailedError, USER_AGENT |
| 24 | +from ..utils import deep_compare, enable_keepalive, iter_response_objects, parse_bool, RetryFailedError, USER_AGENT |
25 | 25 | from . import catch_return_false_exception, Cluster, ClusterConfig, \ |
26 | 26 | Failover, Leader, Member, Status, SyncState, TimelineHistory |
27 | 27 | from .etcd import AbstractEtcd, AbstractEtcdClientWithFailover, catch_etcd_errors, \ |
@@ -66,6 +66,10 @@ class Etcd3Exception(etcd.EtcdException): |
66 | 66 | pass |
67 | 67 |
|
68 | 68 |
|
| 69 | +class Etcd3WatchCanceled(Etcd3Exception): |
| 70 | + pass |
| 71 | + |
| 72 | + |
69 | 73 | class Etcd3ClientError(Etcd3Exception): |
70 | 74 |
|
71 | 75 | def __init__(self, code: Optional[int] = None, error: Optional[str] = None, status: Optional[int] = None) -> None: |
@@ -356,7 +360,6 @@ def handle_auth_errors(self: 'Etcd3Client', func: Callable[..., Any], *args: Any |
356 | 360 | exc = e |
357 | 361 | self._reauthenticate = True |
358 | 362 | if retry: |
359 | | - logger.error('retry = %s', retry) |
360 | 363 | retry.ensure_deadline(0.5, exc) |
361 | 364 | elif reauthenticated: |
362 | 365 | raise exc |
@@ -508,6 +511,8 @@ def _process_message(self, message: Dict[str, Any]) -> None: |
508 | 511 | if 'error' in message: |
509 | 512 | raise _raise_for_data(message) |
510 | 513 | result = message.get('result', EMPTY_DICT) |
| 514 | + if parse_bool(result.get('canceled')): |
| 515 | + raise Etcd3WatchCanceled('Watch canceled') |
511 | 516 | header = result.get('header', EMPTY_DICT) |
512 | 517 | self._check_cluster_raft_term(header.get('cluster_id'), header.get('raft_term')) |
513 | 518 | events: List[Dict[str, Any]] = result.get('events', []) |
@@ -555,8 +560,10 @@ def _build_cache(self) -> None: |
555 | 560 |
|
556 | 561 | try: |
557 | 562 | self._do_watch(result['header']['revision']) |
| 563 | + except Etcd3WatchCanceled: |
| 564 | + logger.info('Watch request canceled') |
558 | 565 | except Exception as e: |
559 | | - # Following exceptions are expected on Windows because the /watch request is done with `read_timeout` |
| 566 | + # Following exceptions are expected on Windows because the /watch request is done with `read_timeout` |
560 | 567 | if not (os.name == 'nt' and isinstance(e, (ReadTimeoutError, ProtocolError))): |
561 | 568 | logger.error('watchprefix failed: %r', e) |
562 | 569 | finally: |
|
0 commit comments