Google 从 Pub/Sub 订阅中提取的 Cloud Function 引发异常 - 已超过截止日期
Google Cloud Function pulling from Pub/Sub subscription throws exception - Deadline Exceeded
我在 Python 3.7 中有一个 Google Cloud Function 以同步拉取模式从 Pub/Sub 订阅中读取。
在 运行 罚款 1/小时 24 小时后,它抛出此异常堆栈跟踪:
Traceback (most recent call last): File
"/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py",
line 57, in error_remapped_callable
return callable_(*args, **kwargs) File "/env/local/lib/python3.7/site-packages/grpc/_channel.py", line 824,
in call
return _end_unary_response_blocking(state, call, False, None) File "/env/local/lib/python3.7/site-packages/grpc/_channel.py", line
726, in _end_unary_response_blocking
raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status =
StatusCode.DEADLINE_EXCEEDED details = "Deadline Exceeded"
debug_error_string =
"{"created":"@1580454091.145703535","description":"Error received from
peer
ipv4:74.125.202.95:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"Deadline
Exceeded","grpc_status":4}"
上述异常是以下异常的直接原因:
回溯(最近调用最后):文件
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
第 346 行,在 run_http_function
中
结果 = _function_handler.invoke_user_function(flask.request) 文件
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
第 217 行,在 invoke_user_function
return call_user_function(request_or_event) 文件“/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py”,
第 210 行,在 call_user_function
return self._user_function(request_or_event) 文件“/user_code/main.py”,第 39 行,在迭代中
响应 = sub.pull(sub_path, MAX_MESSAGES) 文件 "/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/_gapic.py",
第 40 行,在
fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw) # noqa 文件
"/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/gapic/subscriber_client.py",
第 1005 行,在 pull
request, retry=重试, timeout=超时, metadata=元数据文件 "/env/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py",
第 143 行,在 call
return wrapped_func(*args, **kwargs) 文件“/env/local/lib/python3.7/site-packages/google/api_core/retry.py”,
第 286 行,在 retry_wrapped_func
on_error=on_error,文件“/env/local/lib/python3.7/site-packages/google/api_core/retry.py”,
第 184 行,在 retry_target
中
return target() 文件 "/env/local/lib/python3.7/site-packages/google/api_core/timeout.py",
第 214 行,在 func_with_timeout
中
return func(*args, **kwargs) 文件“/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py”,
第 59 行,在 error_remapped_callable
中
six.raise_from(exceptions.from_grpc_error(exc), exc) 文件 "", 第 3 行,在 raise_from
google.api_core.exceptions.DeadlineExceeded: 504 已超过最后期限
这是关于什么的?这是预期的还是某些配置问题的结果?如果在意料之中,应该如何处理?
pull 上的文档(查看源代码:https://googleapis.dev/python/pubsub/latest/subscriber/api/client.html)没有说明这是一个可能的例外。
我在拉取完成后立即确认消息。我一次只允许执行一个函数。我有一个 600 秒的确认期限。一次拉取的一条消息,貌似不到100条。如果这是关于未能确认消息,那么错误似乎可以做得更好。
当订阅中没有消息可读时,客户端会引发此异常。它是来自最新 PubSub 库版本 >= 1.0.0 的 known issue。如有必要,您可以降级到不存在此问题的版本 0.45.0。
但是,作为解决方法,您可以捕获 DeadlineExceeded 异常并重试该操作。此外,基于 comment of Hemang,这里有一个小的 monkeypatch,您可以将其添加到 运行 代码中,这可能有助于获得与版本 0.45.0.
相同的行为
from google.cloud.pubsub_v1.gapic import subscriber_client_config as sub_config
sub_config.config['interfaces']['google.pubsub.v1.Subscriber']['retry_params']['messaging']['initial_rpc_timeout_millis'] = 25000
最后,请记住,在使用同步拉动时,having many outstanding pull requests helps lower the delivery latency, which in turn might result in higher latency pull requests (and DeadlineExceeded errors). Although, if latency is crucial for the application, you could consider using StreamingPull
我在 Python 3.7 中有一个 Google Cloud Function 以同步拉取模式从 Pub/Sub 订阅中读取。
在 运行 罚款 1/小时 24 小时后,它抛出此异常堆栈跟踪:
Traceback (most recent call last): File
"/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py",
line 57, in error_remapped_callable
return callable_(*args, **kwargs) File "/env/local/lib/python3.7/site-packages/grpc/_channel.py", line 824,
in call
return _end_unary_response_blocking(state, call, False, None) File "/env/local/lib/python3.7/site-packages/grpc/_channel.py", line
726, in _end_unary_response_blocking
raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status =
StatusCode.DEADLINE_EXCEEDED details = "Deadline Exceeded"
debug_error_string =
"{"created":"@1580454091.145703535","description":"Error received from
peer
ipv4:74.125.202.95:443","file":"src/core/lib/surface/call.cc","file_line":1056,"grpc_message":"Deadline
Exceeded","grpc_status":4}"上述异常是以下异常的直接原因:
回溯(最近调用最后):文件
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
第 346 行,在 run_http_function
中 结果 = _function_handler.invoke_user_function(flask.request) 文件
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
第 217 行,在 invoke_user_function
return call_user_function(request_or_event) 文件“/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py”,
第 210 行,在 call_user_function
return self._user_function(request_or_event) 文件“/user_code/main.py”,第 39 行,在迭代中
响应 = sub.pull(sub_path, MAX_MESSAGES) 文件 "/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/_gapic.py",
第 40 行,在
fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw) # noqa 文件
"/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/gapic/subscriber_client.py",
第 1005 行,在 pull
request, retry=重试, timeout=超时, metadata=元数据文件 "/env/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py",
第 143 行,在 call
return wrapped_func(*args, **kwargs) 文件“/env/local/lib/python3.7/site-packages/google/api_core/retry.py”,
第 286 行,在 retry_wrapped_func
on_error=on_error,文件“/env/local/lib/python3.7/site-packages/google/api_core/retry.py”,
第 184 行,在 retry_target
中 return target() 文件 "/env/local/lib/python3.7/site-packages/google/api_core/timeout.py",
第 214 行,在 func_with_timeout
中 return func(*args, **kwargs) 文件“/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py”,
第 59 行,在 error_remapped_callable
中 six.raise_from(exceptions.from_grpc_error(exc), exc) 文件 "", 第 3 行,在 raise_from
google.api_core.exceptions.DeadlineExceeded: 504 已超过最后期限
这是关于什么的?这是预期的还是某些配置问题的结果?如果在意料之中,应该如何处理?
pull 上的文档(查看源代码:https://googleapis.dev/python/pubsub/latest/subscriber/api/client.html)没有说明这是一个可能的例外。
我在拉取完成后立即确认消息。我一次只允许执行一个函数。我有一个 600 秒的确认期限。一次拉取的一条消息,貌似不到100条。如果这是关于未能确认消息,那么错误似乎可以做得更好。
当订阅中没有消息可读时,客户端会引发此异常。它是来自最新 PubSub 库版本 >= 1.0.0 的 known issue。如有必要,您可以降级到不存在此问题的版本 0.45.0。
但是,作为解决方法,您可以捕获 DeadlineExceeded 异常并重试该操作。此外,基于 comment of Hemang,这里有一个小的 monkeypatch,您可以将其添加到 运行 代码中,这可能有助于获得与版本 0.45.0.
相同的行为from google.cloud.pubsub_v1.gapic import subscriber_client_config as sub_config
sub_config.config['interfaces']['google.pubsub.v1.Subscriber']['retry_params']['messaging']['initial_rpc_timeout_millis'] = 25000
最后,请记住,在使用同步拉动时,having many outstanding pull requests helps lower the delivery latency, which in turn might result in higher latency pull requests (and DeadlineExceeded errors). Although, if latency is crucial for the application, you could consider using StreamingPull