Bound the wait for a device reply; await the factory command write - #55
Open
GlassOnTin wants to merge 2 commits into
Open
Bound the wait for a device reply; await the factory command write#55GlassOnTin wants to merge 2 commits into
GlassOnTin wants to merge 2 commits into
Conversation
_readReply polled for a reply in an unbounded loop, and because the interval doubled every attempt it stopped being a poll: at the 10ms base, attempt 15 sleeps 5.5 minutes and attempt 20 sleeps 2.9 hours. A device that never answers therefore hangs the caller permanently, with no error and no diagnostic. The failure modes were asymmetric. A device that rejects a command raises NetMDRejected and one that does not implement it raises NetMDNotImplemented, but a device that simply says nothing produced silence. A Sony MDS-JE780 deck does exactly that: it answers the factory-mode auth with "not implemented" on the normal command channel (request 0x80) and does not answer it at all on the factory channel (0xff), so iface.factory() never returns. Cap the interval so this stays a poll, and give up after a total timeout with a NetMDError saying what happened. Both bounds are static, so a caller who needs longer for a slow operation can raise them. The timeout defaults to two minutes, which is far longer than any reply this library waits on in practice.
NetMDFactoryInterface.sendCommand did not await sendFactoryCommand, so the write promise floated: sendQuery calls sendCommand and then readReply, and the reply poll could begin before the command had been written. A failing control transfer also surfaced as an unhandled rejection rather than at the call site.
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 #54.
Two fixes for decks that don't answer:
NetMD._readReply()backoff was unbounded — attempt 15 slept ~5.5 minutes, so an unresponsive deck hung the client forever. Polling now caps at 1 s intervals and gives up after 120 s with a descriptiveNetMDError.NetMDFactoryInterface.sendCommand()never awaitedsendFactoryCommand(), so the reply poll could start before the write completed, and write failures surfaced as unhandled rejections.Found on an MDS-JE780 (
054c:0081), which rejects factory-mode commands: factory queries used to freeze the app with no diagnostics.New tests in
src/netmd-reply.test.tscover the timeout and interval cap against a mock device. 27/28 pass; the remaining failure needs physical hardware (054c:00c8) and fails on master too.tsc --noEmitis clean.