Convert client socket timeout to datastore timeout
This allows the application to catch the timeout as a typical
datastore timeout error.
@@ -24,9 +24,11 @@ index functions, transaction functions.
import collections
import datetime
+import errno
import logging
import os
import time
+import socket
import sys
import threading
import warnings
@@ -344,13 +346,21 @@ class DatastoreDistributed(apiproxy_stub.APIProxyStub):
api_request.set_request_id(request_id)
api_response = remote_api_pb.Response()
- api_response = api_request.sendCommand(self.__datastore_location,
+ try:
+ api_response = api_request.sendCommand(
+ self.__datastore_location,
tag,
api_response,
1,
self.__is_encrypted,
KEY_LOCATION,
CERT_LOCATION)
+ except socket.error as socket_error:
+ if socket_error.errno == errno.ETIMEDOUT:
+ raise apiproxy_errors.ApplicationError(
+ datastore_pb.Error.TIMEOUT,
+ 'Connection timed out when making datastore request')
+ raise
if not api_response or not api_response.has_response():
raise datastore_errors.InternalError(
