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 compatibility with Fiber Scheduler. #987

Merged
merged 4 commits into from
Dec 8, 2023

Conversation

ioquatix
Copy link
Member

@ioquatix ioquatix commented Jun 4, 2023

This is a first pass at improving the compatibility with the fiber scheduler and contains two changes:

  • Ensure the ThreadClient is actually per-thread and not per-fiber.
  • Ensure that waiting for events (blocking) is done in a blocking context, otherwise it will be redirected in the fiber scheduler which is probably not desirable.

It only works on 3.2 but could be made to work on 3.0 and 3.1 if some tests were changed.

Fiber.blocking{...} was introduced in Ruby 3.2. It can be emulated by Fiber.new(blocking: true) {...} but the backtrace is changed. This causes some test failures.

My personal opinion is that we can ignore 3.0 and 3.1 but there is an option to support them with the compatibility wrapper outlined above, if we are willing to change some of the tests that check backtraces.

I cannot see any other obvious issues with the debug code. If there are other places where the debug code is executing blocking operations, we should add more Fiber.blocking{...} to avoid entering the fiber scheduler.

@ioquatix
Copy link
Member Author

ioquatix commented Jun 4, 2023

@ko1 can you please review and also if you want tests, can you suggest what kind of tests to add? The original issue #486 has a complete example and this PR fixes it. However, as you said, you may not want to pull in async to run that sample.

louim added a commit to didacte/debug that referenced this pull request Oct 16, 2023
The patch is mentioned in the following issue:
ruby#987 (comment)
louim added a commit to didacte/debug that referenced this pull request Oct 16, 2023
The patch is mentioned in the following issue:
ruby#987 (comment)
@louim
Copy link

louim commented Oct 17, 2023

Hello! First, thank you @ioquatix for this patch. We are running ruby 3.1 and encountered the bug mentioned in #486. Since this patch is for ruby 3.2+, I went ahead an applied your suggestion to make it work with Ruby 3.1. Here's the branch, rebased on master and with the patch you mentioned. It fixed our problem 🎉 .

I'd be happy to help get this in the debug gem itself. What would be the way forward to make this happen? @ko1, I'd be happy to help in any way I can to get this merged 🚀 .

@louim
Copy link

louim commented Oct 17, 2023

Seems like I spoke too soon 🙃. @ioquatix using Fiber.new(blocking: true) {yield} does not seem to stop the debugger on ruby 3.1. I can see the debugger output appear, but the code continues. Do we need to wrap it with something else?

@ioquatix
Copy link
Member Author

ioquatix commented Oct 20, 2023

@louim can you try with Ruby 3.1.3?

There were some bug fixes which I hope were backported, it might be responsible.

@louim
Copy link

louim commented Oct 21, 2023

@ioquatix sorry, I didn’t mention it, but we are in fact using ruby 3.1.3.

@ioquatix ioquatix force-pushed the fiber-scheduler-compatibility branch from d403e22 to a1375fc Compare October 21, 2023 00:27
@ioquatix
Copy link
Member Author

ioquatix commented Oct 21, 2023

@louim Can you test with this?

    if ::Fiber.respond_to?(:blocking)
      private def fiber_blocking
        ::Fiber.blocking{yield}
      end
    else
      private def fiber_blocking
        ::Fiber.new(blocking: true){yield}.resume
      end
    end

@ioquatix ioquatix force-pushed the fiber-scheduler-compatibility branch 2 times, most recently from 1322696 to 951ffe3 Compare October 21, 2023 01:27
@ioquatix
Copy link
Member Author

With the latest change, the test failures on < 3.2 are stack trace related, as we can't control the stack when using Fiber.new(blocking: true){yield}.resume. So we should skip those tests?

@ioquatix ioquatix force-pushed the fiber-scheduler-compatibility branch from 951ffe3 to 754ade2 Compare December 6, 2023 00:02
@@ -63,7 +63,7 @@ def connect_to_cdp_server
MSG
end

TIMEOUT_SEC = (ENV['RUBY_DEBUG_TIMEOUT_SEC'] || 10).to_i
TIMEOUT_SEC = (ENV['RUBY_DEBUG_TIMEOUT_SEC'] || 30).to_i
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you extend the timeout?
this extension will introduce huge slowdown on some cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

I found the test runner was timing out on GitHub actions even in HEAD.

@ko1 ko1 merged commit 0b32043 into ruby:master Dec 8, 2023
16 of 19 checks passed
ko1 added a commit that referenced this pull request Dec 8, 2023
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://togithub.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://togithub.com/ruby/debug/releases/tag/v1.9.0)

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

#### What's Changed

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

#### New Contributors

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

3 participants