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: Acquire lock when printing text to fix race condition #198

Merged
merged 1 commit into from
Sep 15, 2024

Conversation

gabe565
Copy link
Contributor

@gabe565 gabe565 commented Sep 15, 2024

Hey!

I've been testing the new Bprintf and Bprintln functions, and have found a race condition.

If text is printed at the same time as Write is called, there's a chance that some of the text will not be printed. This is because bytes.Buffer is not thread-safe. In my testing, acquiring a lock in Bprintf and Bprintln fixes the issue.

@schollz
Copy link
Owner

schollz commented Sep 15, 2024

Thanks!

@schollz schollz merged commit e57a85d into schollz:main Sep 15, 2024
1 check passed
renovate bot referenced this pull request in nobl9/sloctl Sep 15, 2024
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[github.com/schollz/progressbar/v3](https://redirect.github.com/schollz/progressbar)
| `v3.14.6` -> `v3.15.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fschollz%2fprogressbar%2fv3/v3.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fschollz%2fprogressbar%2fv3/v3.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fschollz%2fprogressbar%2fv3/v3.14.6/v3.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fschollz%2fprogressbar%2fv3/v3.14.6/v3.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>schollz/progressbar
(github.com/schollz/progressbar/v3)</summary>

###
[`v3.15.0`](https://redirect.github.com/schollz/progressbar/releases/tag/v3.15.0)

[Compare
Source](https://redirect.github.com/schollz/progressbar/compare/v3.14.6...v3.15.0)

#### What's Changed

- new: feature scrolling detail by
[@&#8203;luo-cheng-xi](https://redirect.github.com/luo-cheng-xi) in
[https://github.com/schollz/progressbar/pull/194](https://redirect.github.com/schollz/progressbar/pull/194)
- fix: Acquire lock when printing text to fix race condition by
[@&#8203;gabe565](https://redirect.github.com/gabe565) in
[https://github.com/schollz/progressbar/pull/198](https://redirect.github.com/schollz/progressbar/pull/198)
- fix: change some attribute about time to time.Time{} by
[@&#8203;luo-cheng-xi](https://redirect.github.com/luo-cheng-xi) in
[https://github.com/schollz/progressbar/pull/196](https://redirect.github.com/schollz/progressbar/pull/196)
- fix:fixed the bug that changMax isn't working. by
[@&#8203;luo-cheng-xi](https://redirect.github.com/luo-cheng-xi) in
[https://github.com/schollz/progressbar/pull/193](https://redirect.github.com/schollz/progressbar/pull/193)

#### New Contributors

- [@&#8203;luo-cheng-xi](https://redirect.github.com/luo-cheng-xi) made
their first contribution in
[https://github.com/schollz/progressbar/pull/194](https://redirect.github.com/schollz/progressbar/pull/194)

**Full Changelog**:
schollz/progressbar@v3.14.6...v3.15.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am
every weekday,every weekend" (UTC), Automerge - At any time (no schedule
defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/nobl9/sloctl).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC43NC4xIiwidXBkYXRlZEluVmVyIjoiMzguNzQuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwiZ29sYW5nIiwicmVub3ZhdGUiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants