title: Google Cloud Function pulling from Pub/Sub subscription throws exception - Deadline Exceeded
body: <p>I have a Google Cloud Function in Python 3.7 reading from a Pub/Sub subscription in synchronous pull mode. </p>
  
  <p>After running fine 1/hour for 24 hours, it threw this exception stack trace:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File<br>
    "/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py",<br>
    line 57, in error_remapped_callable<br>
        return callable_(*args, **kwargs)   File "/env/local/lib/python3.7/site-packages/grpc/_channel.py", line 824,<br>
    in <strong>call</strong><br>
        return _end_unary_response_blocking(state, call, False, None)   File "/env/local/lib/python3.7/site-packages/grpc/_channel.py", line<br>
    726, in _end_unary_response_blocking<br>
        raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: &lt;_InactiveRpcError of RPC that terminated with:   status =<br>
    StatusCode.DEADLINE_EXCEEDED  details = "Deadline Exceeded"<br>
      debug_error_string =<br>
    "{"created":"@1580454091.145703535","description":"Error received from<br>
    peer<br>
    ipv4:74.125.202.95:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"Deadline<br>
    Exceeded","grpc_status":4}"  </p>
    
    <blockquote>
      <p></p>
    </blockquote>
    
    <p>The above exception was the direct cause of the following exception:  </p>
    
    <p>Traceback (most recent call last):   File<br>
    "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",<br>
    line 346, in run_http_function<br>
        result = _function_handler.invoke_user_function(flask.request)   File<br>
    "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",<br>
    line 217, in invoke_user_function<br>
        return call_user_function(request_or_event)   File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",<br>
    line 210, in call_user_function<br>
        return self._user_function(request_or_event)   File "/user_code/main.py", line 39, in iteration<br>
        response = sub.pull(sub_path, MAX_MESSAGES)   File "/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/_gapic.py",<br>
    line 40, in <br>
        fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw)  # noqa   File<br>
    "/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/gapic/subscriber_client.py",<br>
    line 1005, in pull<br>
        request, retry=retry, timeout=timeout, metadata=metadata   File "/env/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py",<br>
    line 143, in <strong>call</strong><br>
        return wrapped_func(*args, **kwargs)   File "/env/local/lib/python3.7/site-packages/google/api_core/retry.py",<br>
    line 286, in retry_wrapped_func<br>
        on_error=on_error,   File "/env/local/lib/python3.7/site-packages/google/api_core/retry.py",<br>
    line 184, in retry_target<br>
        return target()   File "/env/local/lib/python3.7/site-packages/google/api_core/timeout.py",<br>
    line 214, in func_with_timeout<br>
        return func(*args, **kwargs)   File "/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py",<br>
    line 59, in error_remapped_callable<br>
        six.raise_from(exceptions.from_grpc_error(exc), exc)   File "", line 3, in raise_from<br>
    google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded  </p>
  </blockquote>
  
  <p>What is this about? Is it to be expected or a result of some configuration problem? If to be expected, how should it be handled?</p>
  
  <p>The documentation ( view-source:<a href="https://googleapis.dev/python/pubsub/latest/subscriber/api/client.html" rel="nofollow noreferrer">https://googleapis.dev/python/pubsub/latest/subscriber/api/client.html</a> ) on pull has nothing about this being a possible exception.</p>
  
  <p>I ack the messages immediately after the pull completes. I only permit one function execution at a time. I have a 600 second acknowledgement deadline. A block of messages pulled at one time seem to be less than 100 in number. If this is about failing to ack a message, it seems like the error could be done much better.</p>