Fix stdout resource leak in find_ssh_servers#45
Open
InterstellarIntruder wants to merge 1 commit into
Open
Conversation
find_ssh_servers redirected sys.stdout manually and only restored it on the happy path. If asyncio.run() raised during LAN or USB scans, stdout could remain redirected to /dev/null and hide all subsequent output. Use nested context managers (open + redirect_stdout) to guarantee stdout restoration and close the devnull handle on both success and exception. Add three tests covering success and failures at both asyncio.run call sites to prove stdout is always restored. Fixes Project-CETI#40
Author
|
Added focused tests for stdout restoration in all three relevant paths (success, first scan failure, second scan failure). If anyone sees a preferred pattern for suppressing |
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.
Fixes #40
find_ssh_servers()was manually redirectingsys.stdoutto/dev/nullfor both LAN and USB scans, but only restoring it on the happy path. Ifasyncio.run()raised, stdout could stay redirected and hide all later output.This replaces manual swapping with nested context managers:
open(os.devnull, "w")to manage the devnull handlecontextlib.redirect_stdout(...)to guarantee stdout restoration on both success and exceptionTests
tests/test_whaletag.pyasyncio.runrestores stdoutasyncio.runrestores stdout