Fix Windows serial hangs and WinError 31 crashes#275
Open
af-t wants to merge 2 commits into
Open
Conversation
af-t
commented
Jul 8, 2026
- Skip slow comports() scan when an explicit port is given, since the Preloader only stays alive ~0.3s
- Set write_timeout so a stuck write can't block forever uninterruptibly, and chunk usbwrite() at the packet size so timeout headroom is real per chunk; abort instead of retrying from a stale position if a write genuinely times out, since pyserial can't say how many bytes already went out
- Bound flush() instead of trusting the driver's unreliable out_waiting/in_waiting reporting, which otherwise hangs indefinitely
- Read DAXML frames staged with explicit lengths instead of one guessed read, fixing both premature "Wrong length" and framing corruption ("Wrong magic"); give the sub-reads real slack against driver jitter
- Only reassign device.timeout when it actually changes, and never reassign it in the resplen=None path, to avoid WinError 31 right after a write burst; lower the constructor default so that path's wait bound is real instead of relying on a stale ambient value
- Propagate serialportname onto Port so reconnects keep the same port
- Fix mtk.py argparse: global options (--vid, --stock, etc.) given before the subcommand were silently reset to their defaults, since every subcommand parser redeclares them via parents=[base] and argparse's subparser dispatch overwrites the parent namespace with the subparser's own defaults
- Skip slow comports() scan when an explicit port is given, since the
Preloader only stays alive ~0.3s
- Set write_timeout so a stuck write can't block forever uninterruptibly,
and chunk usbwrite() at the packet size so timeout headroom is real
per chunk; abort instead of retrying from a stale position if a write
genuinely times out, since pyserial can't say how many bytes already
went out
- Bound flush() instead of trusting the driver's unreliable
out_waiting/in_waiting reporting, which otherwise hangs indefinitely
- Read DAXML frames staged with explicit lengths instead of one guessed
read, fixing both premature "Wrong length" and framing corruption
("Wrong magic"); give the sub-reads real slack against driver jitter
- Only reassign device.timeout when it actually changes, and never
reassign it in the resplen=None path, to avoid WinError 31 right
after a write burst; lower the constructor default so that path's
wait bound is real instead of relying on a stale ambient value
- Propagate serialportname onto Port so reconnects keep the same port
- Fix mtk.py argparse: global options (--vid, --stock, etc.) given
before the subcommand were silently reset to their defaults, since
every subcommand parser redeclares them via parents=[base] and
argparse's subparser dispatch overwrites the parent namespace with
the subparser's own defaults
- Extract shared XFlash/XmlFlash/Legacy logic into extension_common.py mixin - Consolidate register-clear, partition-lookup, and handshake-retry helpers - Unify exploit payload() via PTYPE class attribute across 4 classes - Share ARM instruction decoders in ArchTools, drop dead usblib override
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.