Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory leak when publishing messages #406

Merged
merged 3 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions google/cloud/pubsub_v1/publisher/_batch/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ def commit(self):

def _start_commit_thread(self):
"""Start a new thread to actually handle the commit."""

# NOTE: If the thread is *not* a daemon, a memory leak exists for some reason...
# https://github.com/googleapis/python-pubsub/issues/395#issuecomment-829910303
plamut marked this conversation as resolved.
Show resolved Hide resolved
commit_thread = threading.Thread(
name="Thread-CommitBatchPublisher", target=self._commit
name="Thread-CommitBatchPublisher", target=self._commit, daemon=True
)
commit_thread.start()

Expand Down
6 changes: 5 additions & 1 deletion google/cloud/pubsub_v1/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,12 @@ def _ensure_commit_timer_runs_no_lock(self):

def _start_commit_thread(self):
"""Start a new thread to actually wait and commit the sequencers."""
# NOTE: If the thread is *not* a daemon, a memory leak exists for some reason...
# https://github.com/googleapis/python-pubsub/issues/395#issuecomment-829910303
plamut marked this conversation as resolved.
Show resolved Hide resolved
self._commit_thread = threading.Thread(
name="Thread-PubSubBatchCommitter", target=self._wait_and_commit_sequencers
name="Thread-PubSubBatchCommitter",
target=self._wait_and_commit_sequencers,
daemon=True,
)
self._commit_thread.start()

Expand Down