Skip to content

Add and use #reset!#45

Merged
dledda-r7 merged 1 commit intorapid7:masterfrom
zeroSteiner:fix/io/relay-manager/reuse
Apr 1, 2026
Merged

Add and use #reset!#45
dledda-r7 merged 1 commit intorapid7:masterfrom
zeroSteiner:fix/io/relay-manager/reuse

Conversation

@zeroSteiner
Copy link
Copy Markdown
Contributor

This adds a #reset! method to the FiberScheduler class, which will reset the object back to its initial state. This is necessary if the scheduler will be used again as is the case in the RelayManager. If one or more relays are added then they all exit, the scheduler needs to be reset before it can be used again. This fixes a bug where the relays all exit, then more relays are added. Between the exit of the original relays and the new ones being added, the scheduler was left in a closed state so the new relays were never being processed.

@adfoster-r7
Copy link
Copy Markdown
Contributor

Looks like there's a CI failure:


Failures:

  1) Rex::IO::FiberScheduler#run handles blocking count correctly
     Failure/Error: expect(scheduler.instance_variable_get(:@blocking)).to eq(1)

       expected: 1
            got: 0

       (compared using ==)
     # ./spec/rex/io/fiber_scheduler_spec.rb:232:in `block (3 levels) in <top (required)>'

Finished in 3.61 seconds (files took 0.22652 seconds to load)
114 examples, 1 failure

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR attempts to make Rex::IO::RelayManager reusable across multiple runs by resetting the underlying Rex::IO::FiberScheduler state when the manager thread exits.

Changes:

  • Call @scheduler.reset! when RelayManager#run finishes (in ensure).
  • Introduce FiberScheduler#reset! to clear internal queues/maps and recreate the urgent signaling pipe.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
lib/rex/io/relay_manager.rb Resets the scheduler after the scheduler thread finishes running.
lib/rex/io/fiber_scheduler.rb Adds reset! to clear scheduler state and recreate the urgent wakeup pipe.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@zeroSteiner
Copy link
Copy Markdown
Contributor Author

Looks like that CI failure was a fluke. Rerunning the tests switched it to passing. I don't know about all of these copilot suggestions. It seems pretty intuitive to me that if you #reset! it with pending work that you'll lose it... because you reset it. In practice work wasn't being rescheduled when the manager was being reused to begin with and this fixes that.

@bwatters-r7 bwatters-r7 moved this from Todo to Ready in Metasploit Kanban Mar 23, 2026
@dledda-r7 dledda-r7 self-assigned this Mar 31, 2026
Copy link
Copy Markdown
Contributor

@dledda-r7 dledda-r7 left a comment

Choose a reason for hiding this comment

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

Changes looks good to me

@github-project-automation github-project-automation bot moved this from Ready to In Progress in Metasploit Kanban Apr 1, 2026
@dledda-r7 dledda-r7 merged commit c99bcee into rapid7:master Apr 1, 2026
41 of 42 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Metasploit Kanban Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants