【问题标题】:Docker + pubsub + subprocess hangs with no errorsDocker + pubsub + subprocess 挂起且没有错误
【发布时间】:2020-09-24 07:08:27
【问题描述】:

我在 docker 容器中运行 pubsub,几分钟后遇到挂起。我一直在 docker 之外使用类似的命令运行 pubsub,并且没有看到挂起(运行超过 1 年)。

我能够通过下面概述的简化实现重现我的问题。

以下四个文件(docker file、requirements.txt、worker.py、test.py)放在同一个目录下。它们位于此要点中。基本上 worker.py 调用的是一个子进程函数,它调用 test.py 来运行 time.sleep(3)。

Gist for code and debug outputs

为了构建 docker 文件,我将 Dockerfile、requirements.txt、worker.py 和 test.py 放入一个目录并运行:

docker build --tag=test .

要运行 docker 文件,我执行了以下操作:

docker run -it \
   -e GOOGLE_APPLICATION_CREDENTIALS=/keys/service-account.json \
   -e GRPC_ENABLE_FORK_SUPPORT=false \
   -e GRPC_VERBOSITY=debug \
   -e GRPC_TRACE=all \
   -v /tmp/keys/:/keys/:ro \
   -v /tmp/logs:/logs \
test:latest bash

文件 service-account.json 包含我的 pubsub 密钥。

我在我的 Mac 上运行 docker,但我也经历过使用 kubernetes 和运行 docker 的 Ubuntu 18.04 机器上的相同挂起。问题是几分钟后,pubsub 订阅者变得无响应。以上代码在没有docker的虚拟环境中完美运行。

文件(要点)publish_output.txt 是我的 pubsub 发布者输出的日志文件,并包含消息 ID。

文件subscriber_output.txt(要点)是订阅者日志输出。我将 GRPC_TRACE 设置为 all 并将 GRPC_VERBOSITY 设置为调试。 收到的最后一条成功消息是消息 ID 1253690400552289(subscriber_output.txt 的第 9338 行)。 pubsub 未收到 1253713007710668、1253714609061509、1253713464329969 及以后的消息。

我需要做任何额外的设置吗?不幸的是,我正在从 python 运行自定义 C++ 代码,所以我需要使用子进程。

我的 docker 配置中的当前 python 包:

CacheControl             0.12.6
cachetools               4.1.0
certifi                  2020.4.5.1
chardet                  3.0.4
firebase                 3.0.1
firebase-admin           4.3.0
firestore                0.0.8
google-api-core          1.18.0
google-api-python-client 1.9.1
google-auth              1.16.1
google-auth-httplib2     0.0.3
google-cloud-core        1.3.0
google-cloud-firestore   1.7.0
google-cloud-logging     1.15.0
google-cloud-pubsub      1.5.0
google-cloud-storage     1.28.1
google-resumable-media   0.5.1
googleapis-common-protos 1.52.0
grpc-google-iam-v1       0.12.3
grpcio                   1.29.0
httplib2                 0.18.1
idna                     2.9
iso8601                  0.1.12
msgpack                  1.0.0
pip                      20.1.1
protobuf                 3.12.2
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pytz                     2020.1
requests                 2.23.0
rsa                      4.0
setuptools               46.4.0
six                      1.15.0
uritemplate              3.0.1
urllib3                  1.25.9
wheel                    0.34.2

感谢任何帮助。

谢谢!

【问题讨论】:

    标签: python docker grpc publish-subscribe google-cloud-pubsub


    【解决方案1】:

    看起来问题出在 google-core-api 上。

    我可以按照这里的建议解决它:

    https://github.com/googleapis/python-pubsub/issues/112

    基本上 requirements.txt 应该使用这些版本:

    google-api-python-client <= 1.8.4
    google-api-core <= 1.16.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多