Skip to content

[dogstatsd] Fix race condition in _flush_buffer#602

Closed
NorthIsUp wants to merge 3 commits intoDataDog:masterfrom
NorthIsUp:race_condition
Closed

[dogstatsd] Fix race condition in _flush_buffer#602
NorthIsUp wants to merge 3 commits intoDataDog:masterfrom
NorthIsUp:race_condition

Conversation

@NorthIsUp
Copy link
Copy Markdown

@NorthIsUp NorthIsUp commented Sep 21, 2020

What does this PR do?

fixes bug #439

Description of the Change

copy the global buffer to a local buffer so we can't accidentally flush it twice.

Alternate Designs

self.buffer could be a queue, but that has other issues, this approach should be good enough without the complexity

Verification Process

existing tests should cover this

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@NorthIsUp NorthIsUp requested a review from a team as a code owner September 21, 2020 23:54
@NorthIsUp
Copy link
Copy Markdown
Author

@jd does this look better?

Copy link
Copy Markdown
Contributor

@jd jd left a comment

Choose a reason for hiding this comment

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

I don't think you're going to solve the problem correctly that way, it's a little more complicated that just adding with lock TBH and needs redesign of the API IMHO.

self._send_to_server("\n".join(self.buffer))
self._current_buffer_total_size = 0
self.buffer = []
with self.lock:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This lock is used for socket handling, it's not a great idea to re-use it for another purpose.

This also only solves a potential race around _flush_buffer, while the original bug report mentioned open_buffer as it's the first one to be the issue.

@jd
Copy link
Copy Markdown
Contributor

jd commented Oct 16, 2020

@NorthIsUp are you hitting an issue in particular for working on this?

@github-actions
Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had activity in the last 30 days.
Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity.

@github-actions github-actions bot added the stale Stale - Bot reminder label Nov 16, 2020
@sgnn7
Copy link
Copy Markdown
Contributor

sgnn7 commented Apr 9, 2021

Closing since this was fixed via this PR now

@sgnn7 sgnn7 closed this Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale - Bot reminder

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants