2424
2525# pylint: disable=ungrouped-imports
2626from google .cloud .exceptions import NotFound
27+ from google .cloud .exceptions import GrpcRendezvous
2728from google .cloud .spanner ._helpers import _options_with_prefix
2829from google .cloud .spanner .batch import Batch
2930from google .cloud .spanner .snapshot import Snapshot
@@ -285,6 +286,10 @@ def run_in_transaction(self, func, *args, **kw):
285286 txn .begin ()
286287 try :
287288 func (txn , * args , ** kw )
289+ except GrpcRendezvous as exc :
290+ _delay_until_retry (exc , deadline )
291+ del self ._transaction
292+ continue
288293 except GaxError as exc :
289294 _delay_until_retry (exc , deadline )
290295 del self ._transaction
@@ -318,15 +323,20 @@ def _delay_until_retry(exc, deadline):
318323 :type deadline: float
319324 :param deadline: maximum timestamp to continue retrying the transaction.
320325 """
321- if exc_to_code (exc .cause ) != StatusCode .ABORTED :
326+ if isinstance (exc , GrpcRendezvous ):
327+ cause = exc
328+ else :
329+ cause = exc .cause
330+
331+ if exc_to_code (cause ) != StatusCode .ABORTED :
322332 raise
323333
324334 now = time .time ()
325335
326336 if now >= deadline :
327337 raise
328338
329- delay = _get_retry_delay (exc )
339+ delay = _get_retry_delay (cause )
330340 if delay is not None :
331341
332342 if now + delay > deadline :
@@ -336,7 +346,7 @@ def _delay_until_retry(exc, deadline):
336346# pylint: enable=misplaced-bare-raise
337347
338348
339- def _get_retry_delay (exc ):
349+ def _get_retry_delay (cause ):
340350 """Helper for :func:`_delay_until_retry`.
341351
342352 :type exc: :class:`google.gax.errors.GaxError`
@@ -345,7 +355,7 @@ def _get_retry_delay(exc):
345355 :rtype: float
346356 :returns: seconds to wait before retrying the transaction.
347357 """
348- metadata = dict (exc . cause .trailing_metadata ())
358+ metadata = dict (cause .trailing_metadata ())
349359 retry_info_pb = metadata .get ('google.rpc.retryinfo-bin' )
350360 if retry_info_pb is not None :
351361 retry_info = RetryInfo ()
0 commit comments