Skip to content

Speech: Memory leak when creating SpeechClient instance for each request #6077

@ghost

Description

OS: Linux Debian and Mint 19

Python version: Python 2.7.15rc1

Python package versions:

grpcio==1.15.0
google-api-core==1.4.0
google-auth==1.5.1
google-cloud==0.34.0
google-cloud-speech==0.36.0
googleapis-common-protos==1.5.3

Description:
gRPC channels are not closed when a SpeechClient goes out of scope. The obvious answer may be that we shouldn't construct a SpeechClient for every request, we found that we were running into issues trying to re-use a SpeechClient instance across multiple simultaneous requests (perhaps due to forking limitations of gRPC). Ideally, garbage collection of the SpeechClient instance would clean up any transports it created and any transports could clean up any channels.

Steps to Reproduce:
Run the attached speech_leak.py script on Linux and you'll see the RSS steadily increase for each request..

Workaround:
The leak can be avoided if we manually construct a channel and Transport and pass that to the SpeechClient and then explicitly close the channel after the request is complete using with. See speech_workaround.py for the modified version.

Code Samples:
leak_examples.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: speechIssues related to the Speech-to-Text API.type: questionRequest for information or clarification. Not an issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions