Skip to content

Bound the wait for a device reply; await the factory command write - #55

Open
GlassOnTin wants to merge 2 commits into
cybercase:masterfrom
GlassOnTin:bounded-reply-read
Open

Bound the wait for a device reply; await the factory command write#55
GlassOnTin wants to merge 2 commits into
cybercase:masterfrom
GlassOnTin:bounded-reply-read

Conversation

@GlassOnTin

@GlassOnTin GlassOnTin commented Jul 31, 2026

Copy link
Copy Markdown

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 descriptive NetMDError.
  • NetMDFactoryInterface.sendCommand() never awaited sendFactoryCommand(), 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.ts cover 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 --noEmit is clean.

_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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Device that ignores a command hangs _readReply forever; factory sendCommand drops its write promise

1 participant