fix: release hdc fport so the local port is free after each run - #5
Open
tonycoder-hub wants to merge 2 commits into
Open
fix: release hdc fport so the local port is free after each run#5tonycoder-hub wants to merge 2 commits into
tonycoder-hub wants to merge 2 commits into
Conversation
Signed-off-by: Tony Coder <407243179@qq.com>
Signed-off-by: Tony Coder <407243179@qq.com>
tonycoder-hub
marked this pull request as ready for review
August 20, 2026 10:08
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 codematrixer/hmdriver2#58: after each use the
hdc fportmapping was left in place, so the local port stayed occupied.Cause
hdc fport tcp:<lport> tcp:8012is opened whenHmClient.local_portis first used. The only teardown path wasDriver.__del__→HmClient.release()→hdc fport rm.__del__is not reliable at process exit, and_rm_local_port()read thelocal_portproperty (which opens a new forward if none existed). There was no publicclose()/ context manager /atexitcleanup.Change
fport.Driver.close()/stop()/__enter__/__exit__/atexit/__del__all call the same idempotent release that runshdc fport rm.hdc fport rmuses a 5s timeout so a hungfport rmcannot block process exit.Driversingleton (_instance.clear()).Related: codematrixer#47
codematrixer/hmdriver2#47 (scripts hang after finish) is partly the same lifecycle. Missing teardown left the forward around (codematrixer#58). When
__del__did run,hdc fport rmcould block forever inside_execute_command(also codematrixer#54). The timeout onfport rmaddresses that hang; codematrixer#47 may still need follow-up if something other thanfport rmis holding the interpreter.No Harmony device required. Added mocked tests in
tests/test_hdc_port_lifecycle.py.This PR is on the fork only (not opened against upstream). Does not redo codematrixer#59 lxml, codematrixer#60 current_app, codematrixer#61 textContains, codematrixer#62 foldable dump.