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

Unfreeze threads for some object-evaluating commands #1030

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Oct 26, 2023

There are several commands that evaluate objects and call methods on them, such as:

  • info
  • ls (outline)
  • trace object
  • display

If the called method acquires a mutex shared with another thread (e.g. when using Timeout), then it'd cause a deadlock as all threads are stopped.

For example, if there's an ActiveRecord Relation object stored as a local variable, and the user runs the info command, then it'd call inspect on it and trigger a database query, it could cause a deadlock as described in #877.

This commit fixes the issue by unfreezing all threads before evaluating those commands and freezing them again after receiving the result event.

Note: theoretically there are more commands that evaluate user program's objects, like break Foo#bar calls Foo.instance_method. But in that case the problem would only arise when Foo.instance_method is overridden with something that'd acquire the lock, which is a far unlikely to happen.

There are several commands that evaluate objects and call methods on them,
such as:
- info
- ls (outline)
- trace object
- display

If the called method acquires a mutex shared with another thread (e.g.
when using Timeout), then it'd cause a deadlock as all threads are stopped.

For example, if there's an ActiveRecord Relation object stored as a local
variable, and the user runs the `info` command, then it'd call `inspect`
on it and trigger a database query, it could cause a deadlock as described
in ruby#877.

This commit fixes the issue by unfreezing all threads before evaluating
those commands and freezing them again after receiving the result event.
@st0012 st0012 force-pushed the fix-command-freezing-issue branch from 8a96c3e to c1ec064 Compare October 26, 2023 20:53
@ko1
Copy link
Collaborator

ko1 commented Nov 13, 2023

I'm not sure it is safe because current thread management technique does not have enough quality to control them, but try it.

@ko1 ko1 merged commit 3255b71 into ruby:master Nov 13, 2023
20 checks passed
xjunior referenced this pull request in powerhome/audiences Dec 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [debug](https://github.com/ruby/debug) | `1.8.0` -> `1.9.0` |
[![age](https://developer.mend.io/api/mc/badges/age/rubygems/debug/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/rubygems/debug/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/rubygems/debug/1.8.0/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/rubygems/debug/1.8.0/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>ruby/debug (debug)</summary>

### [`v1.9.0`](https://github.com/ruby/debug/releases/tag/v1.9.0)

[Compare
Source](https://github.com/ruby/debug/compare/v1.8.0...v1.9.0)

#### What's Changed

-   Configuration
- `session_name` config by [@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1036](https://github.com/ruby/debug/pull/1036)
-   CLI
- Require Reline 0.3.8+ to avoid frozen issue by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1020](https://github.com/ruby/debug/pull/1020)
- Fix prompt list size and colorized code line size to match input line
size passed to Reline by [@&#8203;tompng](https://github.com/tompng)
in
[https://github.com/ruby/debug/pull/1010](https://github.com/ruby/debug/pull/1010)
- Fix broken command history when executing debugger on irb by
[@&#8203;takatea](https://github.com/takatea) in
[https://github.com/ruby/debug/pull/997](https://github.com/ruby/debug/pull/997)
- Drop patch for Reline 0.2.7 by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1022](https://github.com/ruby/debug/pull/1022)
- Support IRB console by [@&#8203;st0012](https://github.com/st0012)
in
[https://github.com/ruby/debug/pull/1024](https://github.com/ruby/debug/pull/1024)
-   Remote
- Allow TracePoint reentry during DAP's evaluation by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1026](https://github.com/ruby/debug/pull/1026)
- CDP: Add debuggerId field in the RETURN OBJECT of "Debugger.enable" by
[@&#8203;ono-max](https://github.com/ono-max) in
[https://github.com/ruby/debug/pull/1028](https://github.com/ruby/debug/pull/1028)
- CDP: disable JavaScript engine based autocompletion by
[@&#8203;ono-max](https://github.com/ono-max) in
[https://github.com/ruby/debug/pull/1029](https://github.com/ruby/debug/pull/1029)
- Do not use HEAD request if 1 port by
[@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1035](https://github.com/ruby/debug/pull/1035)
- Show session_name on connection by
[@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1037](https://github.com/ruby/debug/pull/1037)
-   Internal
- Stop assuming Integer#times is written in C by
[@&#8203;k0kubun](https://github.com/k0kubun) in
[https://github.com/ruby/debug/pull/1015](https://github.com/ruby/debug/pull/1015)
- Disable cloned breakpoints trace point events by
[@&#8203;vinistock](https://github.com/vinistock) in
[https://github.com/ruby/debug/pull/1008](https://github.com/ruby/debug/pull/1008)
- Unfreeze threads for some object-evaluating commands by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1030](https://github.com/ruby/debug/pull/1030)
- Prevent backtrace from hanging if objects in the backtrace use Thread
in inspect by [@&#8203;vinistock](https://github.com/vinistock) in
[https://github.com/ruby/debug/pull/1038](https://github.com/ruby/debug/pull/1038)
- Compile iseq_collector.c logic only on CRuby by
[@&#8203;eregon](https://github.com/eregon) in
[https://github.com/ruby/debug/pull/1039](https://github.com/ruby/debug/pull/1039)
- Fix compatibility with Fiber Scheduler. by
[@&#8203;ioquatix](https://github.com/ioquatix) in
[https://github.com/ruby/debug/pull/987](https://github.com/ruby/debug/pull/987)
- Do not make a Fiber for commands by
[@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1044](https://github.com/ruby/debug/pull/1044)
- support Ruby 3.3 by [@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1045](https://github.com/ruby/debug/pull/1045)
-   Misc/Doc
- Fix ruby warnings by [@&#8203;y-yagi](https://github.com/y-yagi) in
[https://github.com/ruby/debug/pull/993](https://github.com/ruby/debug/pull/993)
- Fix a typo by [@&#8203;makenowjust](https://github.com/makenowjust)
in
[https://github.com/ruby/debug/pull/988](https://github.com/ruby/debug/pull/988)
- Update `TrapInterceptor` to avoid assigning to an unused variable by
[@&#8203;DavidZivk](https://github.com/DavidZivk) in
[https://github.com/ruby/debug/pull/985](https://github.com/ruby/debug/pull/985)
- remove debug print by [@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1043](https://github.com/ruby/debug/pull/1043)
- Minor punctuation and grammar fixes by
[@&#8203;ahangarha](https://github.com/ahangarha) in
[https://github.com/ruby/debug/pull/1041](https://github.com/ruby/debug/pull/1041)
-   Tests
- Bump actions/checkout from 3 to 4 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/ruby/debug/pull/1014](https://github.com/ruby/debug/pull/1014)

#### New Contributors

- [@&#8203;dependabot](https://github.com/dependabot) made their first
contribution in
[https://github.com/ruby/debug/pull/1014](https://github.com/ruby/debug/pull/1014)
- [@&#8203;tompng](https://github.com/tompng) made their first
contribution in
[https://github.com/ruby/debug/pull/1010](https://github.com/ruby/debug/pull/1010)
- [@&#8203;takatea](https://github.com/takatea) made their first
contribution in
[https://github.com/ruby/debug/pull/997](https://github.com/ruby/debug/pull/997)
- [@&#8203;y-yagi](https://github.com/y-yagi) made their first
contribution in
[https://github.com/ruby/debug/pull/993](https://github.com/ruby/debug/pull/993)
- [@&#8203;DavidZivk](https://github.com/DavidZivk) made their first
contribution in
[https://github.com/ruby/debug/pull/985](https://github.com/ruby/debug/pull/985)
- [@&#8203;eregon](https://github.com/eregon) made their first
contribution in
[https://github.com/ruby/debug/pull/1039](https://github.com/ruby/debug/pull/1039)
- [@&#8203;ahangarha](https://github.com/ahangarha) made their first
contribution in
[https://github.com/ruby/debug/pull/1041](https://github.com/ruby/debug/pull/1041)
- [@&#8203;ioquatix](https://github.com/ioquatix) made their first
contribution in
[https://github.com/ruby/debug/pull/987](https://github.com/ruby/debug/pull/987)

**Full Changelog**:
ruby/debug@v1.8.0...v1.9.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **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 has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/powerhome/audiences).

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

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
Development

Successfully merging this pull request may close these issues.

2 participants