Repository navigation
feat: device lifecycle events, opt-in auto-reconnect with backoff, and TCP keepalive - #75
Merged
Merged
Conversation
…d TCP keepalive A dropped connection used to go unnoticed until the next call threw "Device not connected", and nothing reconnected it. Each device now emits lifecycle events (connecting, connected, disconnected, reconnecting, reconnected, error, gave-up) through on/once/off, honouring the existing emitEvents config. connect() takes a new autoReconnect option (default off). When on, an unexpected drop schedules reconnect attempts with exponential backoff and jitter (initialDelay defaults to the retryDelay config, plus factor, maxDelay and maxAttempts). An explicit disconnect() or remove() never triggers it, an explicit reconnect() cancels a pending attempt, and an authentication rejection stops retrying with gave-up. The keepAlive and keepAliveInterval config values, previously unused, now enable TCP keepalive on each connection socket. A failed handshake now destroys its socket instead of leaving it open, so each auto-reconnect retry no longer leaks one.
ADB has no ping message, so connect() takes a new heartbeat option (default off, interval 15s, timeout 5s) that runs a trivial shell command on a timer. A probe that fails or times out closes the socket: the device emits error, then disconnected with reason "heartbeat", and autoReconnect takes over when enabled. Probes stop on any disconnect and never overlap. The disconnected event now also carries a reason ("requested", "closed" or "heartbeat").
Shinrai
approved these changes
Oct 9, 2026
cldmv-bot Bot
added a commit
that referenced
this pull request
Oct 9, 2026
# DroidSock v2.1.0 Changelog **Release Date**: October 2026 **Release Type**: Minor --- ## Overview v2.1.0 gives a device a connection lifecycle. A dropped connection used to go unnoticed until the next call threw "Device not connected", and nothing reconnected it. Each device now emits lifecycle events, can reconnect on its own with exponential backoff, enables TCP keepalive, and can optionally probe the device with a heartbeat to catch a hung `adbd`. All of it is opt-in or additive: existing code that never passes the new options behaves as before, apart from TCP keepalive now being switched on by the `keepAlive` config value that was previously ignored. The release also raises `engines.node` to `>=22.15.0` to match `@cldmv/slothlet` 3.22, and carries the dependency bumps queued since v2.0.3 and a development-toolchain security fix. --- ## ✨ Features ### Lifecycle events ([#75](#75)) Every device emits `connecting`, `connected`, `disconnected`, `reconnecting`, `reconnected`, `error` and `gave-up`, subscribed to with `on(event, listener)`, `once(event, listener)` and `off(event, listener)` (each returns the device, so calls chain). Every payload carries `deviceId`, `host` and `port`. `disconnected` also reports whether the close was `intentional` (a `disconnect()` or `remove()` call) and a `reason` of `"requested"`, `"closed"` or `"heartbeat"`. The events honour the existing `emitEvents` config option, a throwing listener is logged without affecting the connection, and `error` is only emitted when a listener is attached. ### Opt-in auto-reconnect with backoff ([#75](#75)) `device.connect(host, port, { autoReconnect })` reconnects after an unexpected drop. `true` uses the defaults; an object overrides them: `initialDelay` (default: the `retryDelay` config value, 1000 ms), `factor` (2), `maxDelay` (30000 ms), `jitter` (0.2) and `maxAttempts` (unlimited). An explicit `disconnect()` or `remove()` never triggers it, an explicit `reconnect()` cancels a pending automatic attempt, and a device that rejects authentication stops the retries with `gave-up` (reason `"auth"`). After `maxAttempts` consecutive failures the device emits `gave-up` (reason `"max-attempts"`). ### TCP keepalive ([#75](#75)) The `keepAlive` and `keepAliveInterval` config values, which were defined but never read, now enable TCP keepalive on each connection socket (default on, 30 s). A silently dead link is eventually closed by the operating system and reported as a drop. ### Optional heartbeat ADB has no ping message, so `device.connect(host, port, { heartbeat })` runs a trivial shell command on a timer (`true` means every 15 s with a 5 s timeout; an object sets `interval` and `timeout`). A probe that fails or times out closes the socket: the device emits `error`, then `disconnected` with reason `"heartbeat"`, and `autoReconnect` takes over when enabled. Probes never overlap and stop on any disconnect. `docs/API.md` documents the options and the event table under "Lifecycle events". --- ## 🐛 Bug Fixes ### A failed handshake no longer leaks its socket ([#75](#75)) When the handshake failed (authentication rejected, or an unexpected reply), the connection was rejected but its socket stayed open. With auto-reconnect, every failed retry would have left one behind. The socket is now destroyed on a failed handshake. ### `engines.node` now matches `@cldmv/slothlet` 3.22 ([#74](#74)) `@cldmv/slothlet` 3.22 requires Node.js `>=22.15.0`, but the package declared `>=22.12.0`, so installs on Node.js 22.12 to 22.14 resolved with an engines warning for a dependency the package cannot run on. `engines.node`, the CI minimum-Node default and the README requirement are now `>=22.15.0`. --- ## 🔒 Security ### `brace-expansion` 5.0.9 → 5.0.12 ([#66](#66)) Fixes GHSA-q2hr-2g5m-vwhr (CVE-2026-102277), a medium-severity (CVSS 5.3) denial of service: expanding input shaped like `{a},b}` takes time quadratic in the number of literal `}` characters. `brace-expansion` is a transitive dependency of `minimatch`, which only the development tooling pulls in, and the lockfile records it as development-only, so it is not part of the installed package. The repository's Dependabot alert for it ([alert 3](https://github.com/CLDMV/droidsock/security/dependabot/3)) closes once this release reaches `master`. --- ## 🔧 Dependencies Runtime: - `@cldmv/slothlet`: the lockfile moves from 3.21.0 to 3.22.0 ([#70](#70)). The declared range stays `^3.15.0`. The 3.22.0 release adds `api.slothlet.restart()`, an `around` hook type and per-instance helper modules, and raises the minimum Node.js version to 22.15.0 (reflected in `engines.node` above). Dev-only: - **Patch group** ([#72](#72)): `@cldmv/vitest-runner` 1.5.1 → 1.5.3, `@cldmv/jsonv` 1.1.1 → 1.1.3, `@cldmv/eslint-plugin-jsonv` 1.0.13 → 1.0.15, `@cldmv/prettier-plugin-jsonv` 1.1.0 → 1.1.3 and `@types/node` 26.6.3 → 26.6.4. - **Minor group** ([#70](#70)): `globals` 17.12.0 → 17.13.0, alongside the `@cldmv/slothlet` bump above. - **ESLint** ([#68](#68)): `eslint` 10.11.0 → 10.12.0. - **Vitest group** ([#67](#67)): `vitest`, `@vitest/coverage-v8`, `@vitest/mocker` and `@vitest/spy` 5.0.2 → 5.0.3, with `vite` 8.3.1 → 8.3.2 and `rolldown` 1.2.11 → 1.2.12. - **Security** ([#66](#66)): `brace-expansion`, described above. --- ## 📚 Documentation - **NEW:** [docs/changelog/v2/v2.1.0.md](./v2.1.0.md): this changelog. - `docs/API.md`: the `autoReconnect` and `heartbeat` options and the lifecycle event table. - README **✨ What's New** updated for v2.1.0. --- ## Upgrade notes - No breaking changes. Without the new options a device behaves as before; the one default-on difference is TCP keepalive, driven by the `keepAlive` config value. - Use Node.js 22.15 or later (any Node.js 24 or 26 release qualifies). `engines.node` now says so, matching what `@cldmv/slothlet` 3.22 already required. - To keep a long-lived device connected, pass `{ autoReconnect: true, heartbeat: true }` to `device.connect()` and listen for `reconnecting`, `reconnected` and `gave-up`. <details> <summary>👥 Contributors</summary> - @Shinrai </details> --- <!-- coverage-start -->  | Metric | Coverage | |--------|----------| | Statements | 93.4% | | Branches | 85.8% | | Functions | 94.7% | | Lines | 95.0% | *Avg: **92.2%** · `f8bb7ec` · Node lts/** <!-- coverage-end --> <!-- co-authors --> Co-authored-by: Shinrai <[email protected]>
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.
🚀 What's Changed
💥 Breaking Changes
No breaking changes
✨ Features
🐛 Bug Fixes
No bug fixes
📦 Dependencies
No dependency updates
🔧 Other Changes
No other changes
👥 Contributors