Skip to content

Fix trace client memory leak#6856

Merged
tseaver merged 4 commits into
googleapis:masterfrom
c24t:cache-trace-api
Dec 7, 2018
Merged

Fix trace client memory leak#6856
tseaver merged 4 commits into
googleapis:masterfrom
c24t:cache-trace-api

Conversation

@c24t
Copy link
Copy Markdown
Contributor

@c24t c24t commented Dec 6, 2018

cc @liyanhui1228

@bogdandrutu and I are seeing a persistent memory leak in projects using the opencensus stackdriver exporter, which uses google.cloud.trace.client.Client and repeatedly calls batch_write_spans.

Reusing the trace client's API object fixes the leak.

@c24t c24t requested a review from crwilcox as a code owner December 6, 2018 00:27
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 6, 2018
@bogdandrutu
Copy link
Copy Markdown

@crwilcox please help us to submit this and do a patch release if possible. Thank you

@ocervell
Copy link
Copy Markdown

ocervell commented Dec 6, 2018

@c24t Thanks for this ! This might actually fix some issues we've been running into where 'too many open files' exceptions crash our VM. Those start occurring because we keep creating new clients / new connections.

@bogdandrutu
Copy link
Copy Markdown

When we debug this issue we saw also socket objects being leaked, so I think it is a correlation.

Copy link
Copy Markdown
Contributor

@tseaver tseaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! We need test coverage for the case that the backing variable is already set, in both the v1 client unit tests and the v2 client unit tests. The new test would look something like:

    def test_trace_api_existing(self):
        credentials = _make_credentials()
        client = self._make_one(project=self.project, credentials=credentials)
        client._trace_api = mock.sentinel.trace_api

        self.assertIs(client.trace_api, mock.sentinel.trace_api

@c24t
Copy link
Copy Markdown
Contributor Author

c24t commented Dec 6, 2018

Thanks @tseaver, updated in 57a3da4.

@tseaver tseaver added api: cloudtrace Issues related to the Cloud Trace API. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 7, 2018
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 7, 2018
Comment thread trace/tests/unit/v2/test_client_v2.py Outdated
"""Check that the client caches _trace_api."""
client = self._make_one(project=self.project,
credentials=_make_credentials())
self.assertIsNone(client._trace_api)

This comment was marked as spam.

This comment was marked as spam.

@tseaver tseaver merged commit c0abaa4 into googleapis:master Dec 7, 2018
@tseaver
Copy link
Copy Markdown
Contributor

tseaver commented Dec 7, 2018

Thanks for bearing with me, @c24t!

@c24t c24t deleted the cache-trace-api branch December 7, 2018 18:17
ahmetb pushed a commit to GoogleCloudPlatform/microservices-demo that referenced this pull request Dec 12, 2018
Enables tracing in the email and recommendation services, which was disabled in 316db88 because of a memory leak in the stackdriver exporter.

We fixed the leak in googleapis/google-cloud-python#6856. The fix is included in the [0.1.10 release of opencensus-python](https://github.com/census-instrumentation/opencensus-python/releases/tag/v0.1.10).

With this diff, traces show up as expected in stackdriver while running the demo on GKE. Using an `opencensus-python` package version before `0.1.10` causes the email and recommendation services to leak memory until they OOM. Memory use is back to normal (i.e. roughly constant) using the new package version.
neptune-web added a commit to neptune-web/kubernetes-microservices-sam that referenced this pull request Jun 12, 2022
Enables tracing in the email and recommendation services, which was disabled in 316db88 because of a memory leak in the stackdriver exporter.

We fixed the leak in googleapis/google-cloud-python#6856. The fix is included in the [0.1.10 release of opencensus-python](https://github.com/census-instrumentation/opencensus-python/releases/tag/v0.1.10).

With this diff, traces show up as expected in stackdriver while running the demo on GKE. Using an `opencensus-python` package version before `0.1.10` causes the email and recommendation services to leak memory until they OOM. Memory use is back to normal (i.e. roughly constant) using the new package version.
parthea pushed a commit that referenced this pull request Oct 22, 2023
oplik0 pushed a commit to oplik0/bso that referenced this pull request Jun 6, 2024
Enables tracing in the email and recommendation services, which was disabled in 316db88 because of a memory leak in the stackdriver exporter.

We fixed the leak in googleapis/google-cloud-python#6856. The fix is included in the [0.1.10 release of opencensus-python](https://github.com/census-instrumentation/opencensus-python/releases/tag/v0.1.10).

With this diff, traces show up as expected in stackdriver while running the demo on GKE. Using an `opencensus-python` package version before `0.1.10` causes the email and recommendation services to leak memory until they OOM. Memory use is back to normal (i.e. roughly constant) using the new package version.
Anki15201 pushed a commit to Anki15201/microservices-demo that referenced this pull request Jul 26, 2025
Enables tracing in the email and recommendation services, which was disabled in 316db88 because of a memory leak in the stackdriver exporter.

We fixed the leak in googleapis/google-cloud-python#6856. The fix is included in the [0.1.10 release of opencensus-python](https://github.com/census-instrumentation/opencensus-python/releases/tag/v0.1.10).

With this diff, traces show up as expected in stackdriver while running the demo on GKE. Using an `opencensus-python` package version before `0.1.10` causes the email and recommendation services to leak memory until they OOM. Memory use is back to normal (i.e. roughly constant) using the new package version.
dream-work-dev added a commit to dream-work-dev/microservices-demo that referenced this pull request Aug 12, 2025
Enables tracing in the email and recommendation services, which was disabled in 316db88 because of a memory leak in the stackdriver exporter.

We fixed the leak in googleapis/google-cloud-python#6856. The fix is included in the [0.1.10 release of opencensus-python](https://github.com/census-instrumentation/opencensus-python/releases/tag/v0.1.10).

With this diff, traces show up as expected in stackdriver while running the demo on GKE. Using an `opencensus-python` package version before `0.1.10` causes the email and recommendation services to leak memory until they OOM. Memory use is back to normal (i.e. roughly constant) using the new package version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: cloudtrace Issues related to the Cloud Trace API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants