Skip to content

When I publish a data to pubsub topic, I have a memory leak on kubernetes pod. #395

@fodrh1201

Description

@fodrh1201

Each time a public request is made, the memory in the pod of Kubernetes increases. Removing the publishing part does not increase memory.
The pod is continuously restarted due to OOM.

Environment details

  • OS type and version: Debian GNU/Linux 10
  • Python version: 3.8.7
  • pip version: 21.0.1
  • google-cloud-pubsub version: 2.4.1

Code example

class PublishToPubsubCallback(Callback):
    def __init__(self, pod_name, project_id, topic_id, preprocess=[]):
        super(PublishToPubsubCallback, self).__init__(pod_name, preprocess=preprocess)
        self.project_id = project_id
        self.topic_id = topic_id
        self.publisher = pubsub_v1.PublisherClient()
        self.topic_path = self.publisher.topic_path(project_id, topic_id)
        
    def __call__(self, data):
        pub_data = json.dumps(data).encode('utf-8')
        self.publisher.publish(self.topic_path, pub_data)

callback = PublishToPubsubCallback(pod_name, project_id, topic_id)

async def run():
    while True:
        data = await watch_websocket_data()
        callback(data)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

스크린샷 2021-04-23 오후 4 58 16

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: pubsubIssues related to the googleapis/python-pubsub API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions