Fix asyncio event loop initialization on Windows#1724
Open
uceka wants to merge 1 commit intonccgroup:masterfrom
Open
Fix asyncio event loop initialization on Windows#1724uceka wants to merge 1 commit intonccgroup:masterfrom
uceka wants to merge 1 commit intonccgroup:masterfrom
Conversation
Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a runtime error when running ScoutSuite on Windows with recent Python versions (e.g. 3.12), where
asyncio.get_event_loop()raises:The issue occurs in
ScoutSuite/__main__.pyin therunfunction, which currently assumes thatasyncio.get_event_loop()will always return an event loop on the main thread.Root cause
On Windows with newer Python versions,
asyncio.get_event_loop()may raise aRuntimeErrorif no event loop has been set for the current thread yet, or if the previously used loop has been closed. In that situation, the current code path fails before the async workflow can even start.Fix
This change makes the event loop initialization more robust by:
asyncio.get_event_loop()call in a try/except block.asyncio.set_event_loop()when needed.Updated snippet in
run:This approach keeps the existing structure (using a single loop and
run_until_complete) but avoids the crash when no loop is present yet.Testing
Environment:
Steps performed:
python scout.py azure -cbefore the change on Windows and observed:RuntimeError: There is no current event loop in thread 'MainThread'.python scout.py azure -cand confirmed that the event loop error no longer occurs.No other functional behavior changes are intended by this PR.