从发布/订阅订阅中提取的Google Cloud Function引发异常-超过截止日期 [英] Google Cloud Function pulling from Pub/Sub subscription throws exception - Deadline Exceeded

查看:274
本文介绍了从发布/订阅订阅中提取的Google Cloud Function引发异常-超过截止日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python 3.7中的Google Cloud Function,它以同步请求模式从Pub/Sub订阅中读取.

I have a Google Cloud Function in Python 3.7 reading from a Pub/Sub subscription in synchronous pull mode.

在每小时1小时正常运行24小时后,它抛出了此异常堆栈跟踪:

After running fine 1/hour for 24 hours, it threw this exception stack trace:

回溯(最近通话最近一次):文件
"/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py",
第57行,在error_remapped_callable
返回callable _(* args,** kwargs)文件"/env/local/lib/python3.7/site-packages/grpc/_channel.py",第824行,
通话
中 返回_end_unary_response_blocking(状态,调用,False,无)文件"/env/local/lib/python3.7/site-packages/grpc/_channel.py",第
行 726,在_end_unary_response_blocking
引发_InactiveRpcError(state)grpc._channel._InactiveRpcError:< _InactiveRpcError的RPC终止于:status =
StatusCode.DEADLINE_EXCEEDED详细信息=已超过最后期限"
debug_error_string =
"{" created:" @ 1580454091.145703535," description:"收到来自
的错误 同行
ipv4:74.125.202.95:443,"文件:" src/core/lib/surface/call.cc," file_line:1056," grpc_message:"最后期限
超过," grpc_status:4}"

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}"

上述异常是以下异常的直接原因:

The above exception was the direct cause of the following exception:

回溯(最近通话最近一次):文件
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
在run_http_function
中的第346行 结果= _function_handler.invoke_user_function(flask.request)文件
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
第217行,invoke_user_function
返回call_user_function(request_or_event)文件"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
第210行,在call_user_function
中 返回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
请求,重试=重试,超时=超时,元数据=元数据文件"/env/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py",
第143行,在致电
返回wrapd_func(* args,** kwargs)文件"/env/local/lib/python3.7/site-packages/google/api_core/retry.py",
retry_wrapped_func中的第286行
on_error = on_error,文件"/env/local/lib/python3.7/site-packages/google/api_core/retry.py",
retry_target
中的第184行 返回target()文件"/env/local/lib/python3.7/site-packages/google/api_core/timeout.py",
214行,在func_with_timeout
返回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个截止日期

Traceback (most recent call last): File
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
line 346, in run_http_function
result = _function_handler.invoke_user_function(flask.request) File
"/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
line 217, in invoke_user_function
return call_user_function(request_or_event) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py",
line 210, in call_user_function
return self._user_function(request_or_event) File "/user_code/main.py", line 39, in iteration
response = sub.pull(sub_path, MAX_MESSAGES) File "/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/_gapic.py",
line 40, in
fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw) # noqa File
"/env/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/gapic/subscriber_client.py",
line 1005, in pull
request, retry=retry, timeout=timeout, metadata=metadata File "/env/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py",
line 143, in call
return wrapped_func(*args, **kwargs) File "/env/local/lib/python3.7/site-packages/google/api_core/retry.py",
line 286, in retry_wrapped_func
on_error=on_error, File "/env/local/lib/python3.7/site-packages/google/api_core/retry.py",
line 184, in retry_target
return target() File "/env/local/lib/python3.7/site-packages/google/api_core/timeout.py",
line 214, in func_with_timeout
return func(*args, **kwargs) File "/env/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py",
line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc) File "", line 3, in raise_from
google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded

这是什么意思?是预期的还是某些配置问题的结果?如果可以预料,应该如何处理?

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?

文档(查看源: https://googleapis.拉上的dev/python/pubsub/latest/subscriber/api/client.html )对此没有任何可能的例外.

The documentation ( view-source:https://googleapis.dev/python/pubsub/latest/subscriber/api/client.html ) on pull has nothing about this being a possible exception.

提取完成后,我会立即确认消息.我一次只允许执行一个功能.我有600秒的确认截止日期.一次拉出的消息块的数量似乎少于100.如果这是关于无法确认消息的信息,则似乎可以更好地解决该错误.

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.

推荐答案

当订阅中没有要读取的消息时,客户端会引发此异常.这是最新的PubSub库版本> = 1.0.0中的已知问题. .如有必要,可以降级到不存在此问题的0.45.0版本.

This exception is raised by the client when there's no messages to read in the subscription. It is a known issue from the latest PubSub library versions >= 1.0.0. If necessary, you can downgrade to the version 0.45.0 where this issue was not present.

但是,作为解决方法,您可以捕获DeadlineExceeded异常,然后重试该操作.另外,根据 Hemang的评论,这里有一个小您可以将其添加到运行的代码中,这可能有助于获得与0.45.0版相同的行为.

However, as a workaround you can catch the DeadlineExceeded exception and retry the operation again. Also, based on the comment of Hemang, here's a small monkeypatch that you can add to your running code, which might help to get the same behavior as in version 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

最后,请记住,在使用同步拉取时,拥有许多出色的拉取请求有助于降低传递延迟,这反过来可能导致延迟增加的拉取请求(以及DeadlineExceeded错误).虽然,如果延迟对于应用程序至关重要,您可以考虑使用 StreamingPull

Finally, keep in mind that when using synchronous pull, 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

这篇关于从发布/订阅订阅中提取的Google Cloud Function引发异常-超过截止日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆