Skip to content

Android: Stop and Start no longer leave the socket name taken; a camex link is used once (1.16.1) - #103

Merged
compot-dev merged 2 commits into
masterfrom
fix/android-socket-101
Nov 18, 2026
Merged

compot-dev merged 2 commits into
masterfrom
fix/android-socket-101

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Closes #101. Also the "Reopening from recents reapplies an old camex link" finding of the review of #102.

  • Socket name still taken after Stop (Android: a quick Stop and Start can leave vectis not running (socket name still in use) #101): stopVectis() now connects to the abstract socket before closing it, which wakes serve() out of its blocking accept(); serve() sees it is no longer the current server, closes that connection without handing over an fd, and returns, so the name is released. If a start still finds the name taken, it says so and tries again every second, up to 10 times (on the main thread's handler, and only while the user has not pressed Stop), instead of giving up for good.
  • camex link used once: openLink() clears the activity's intent after reading the link and ignores an intent with FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, so reopening the app from recents no longer opens the settings filled from the link that started it.
  • Version 1.16.1, CHANGELOG.

Testing:

  • gradle assembleDebug testDebugUnitTest lintDebug in compot/android:2026.10: 23 unit tests pass.
  • Android 10 TV box (aceline-1, CH340, camex tunnel on): Stop, then Start 5 s later, three times in a row: each time vectis came back (web server ready, the adapter opened), the tunnel came back, and the page answered on the LAN and through the camex server's nginx; no "Address already in use". Before the fix the same sequence left vectis down (see Android: a quick Stop and Start can leave vectis not running (socket name still in use) #101).
  • am start -a VIEW -d camex://connect?... -f 0x00100000 (launched from history): no settings dialog; the same link without the flag: the dialog opens filled in.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Android: Release socket on Stop and consume camex links once

🐞 Bug fix 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Wake the socket server during Stop and retry failed binds so Start can recover.
• Consume camex links once, preventing recents from reopening link-filled settings.
• Document both fixes and bump the vectis version to 1.16.1.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 3 capabilities

  • 3 affected capabilities span independent functional scopes: Android vectis runtime, Camex tunnel configuration integration, Native vectis version reporting.
  • The changed socket lifecycle is the shared activation boundary for one end-to-end behavior: obtaining the USB adapter fd, starting the native vectis process, and exposing its console/web surfaces.
  • The socket, process, and user-facing ports are implementation hops of that runtime behavior rather than independent capabilities.
  • This is a distinct user outcome from the USB runtime: an external camex link populates tunnel configuration in the settings UI.
  • The activity intent and settings form are propagation hops within that bounded camex integration.
  • Version reporting is independent of the Android socket lifecycle and camex settings integration: it affects identification text rather than USB serving or tunnel configuration.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before, Stop closed the socket and a subsequent start attempted one bind.
  • After, Stop wakes an accept loop, the server identity is checked by the fd-serving thread, and bind failure enters a bounded delayed retry state.
  • The new correctness condition is that Stop, stale accept threads, retry callbacks, service wanted state, and a later successful bind must agree on which socket generation is current.
  • The stale-server check and wake-up are targeted lifecycle coordination; the retry-counter exhaustion behavior is a newly relevant state transition.
Potential damage 🟡 Medium 🩹 Temporary loss

  • The concrete failure is loss of the Android vectis runtime and its console/web access, not corruption of USB state or persistent configuration.
  • Reverting the code restores the prior lifecycle, but does not itself release an already-held socket.
  • Supported recovery is a new service instance or release of the stale socket followed by a fresh start; no state repair or external compensation is required.
  • Recoverable by service recreation/Stop-then-Start after the old socket owner exits, assuming the socket is no longer held.
  • The ten-retry exhaustion path is not automatically repaired within the same service instance.
Assessed commit d85a5e9 > Snapshot assessment: the current PR revision could not be verified.
Diagram

graph TD
  A["Stop or Start"] --> B["VectisService"] --> C["Abstract socket"] --> D["FD server"]
  B --> E["Bind retry"]
  F["Camex link"] --> G["MainActivity"] --> H["Settings dialog"]
Loading
High-Level Assessment

Waking the blocked accept before closing the socket addresses the reported ownership problem directly; bounded retries cover a lingering bind without making Stop ineffective. Filtering history launches and clearing the activity intent is appropriate for one-time link handling.

Files changed (4) +57 / -6

Bug fix (2) +45 / -5
MainActivity.javaPrevent camex links from reopening via recents +10/-3

Prevent camex links from reopening via recents

• Clears the activity intent after reading a VIEW link and skips the settings dialog when the intent was launched from history.

android/app/src/main/java/org/openipc/vectis/MainActivity.java

VectisService.javaRelease the socket on Stop and retry failed binds +35/-2

Release the socket on Stop and retry failed binds

• Wakes the blocked socket accept during Stop and prevents its connection from receiving an FD. Adds bounded, delayed bind retries that check whether the service is still wanted.

android/app/src/main/java/org/openipc/vectis/VectisService.java

Documentation (1) +11 / -0
CHANGELOG.mdDocument the 1.16.1 Android fixes +11/-0

Document the 1.16.1 Android fixes

• Adds release notes for the Stop/Start socket recovery and one-time camex link handling.

CHANGELOG.md

Other (1) +1 / -1
vectis.cBump the vectis version to 1.16.1 +1/-1

Bump the vectis version to 1.16.1

• Changes the program version string from 1.16.0 to 1.16.1.

vectis.c

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Stop/start and recents fixes lack tests ✓ Resolved
Description
openLink() now clears the activity intent and skips showSettings when
FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY is set, and startVectis() gains a 10-try, 1-second bind
retry gated on Settings.running and isWanted(). Neither behaviour has a regression test in this
diff, and the PR relies on a manual Android 10 TV run plus the existing 23 unit tests, so a later
change to the flag check or the retry condition could reintroduce #101 or #102 without any test
failing.

2. A later Start cannot retry the socket ✓ Resolved
Description
bindTries increases on every failed bind but resets only after a successful bind, not when
stopVectis() ends a run. After ten failures, a user who presses Stop and then Start while the name
is still occupied gets one failed bind with no delayed retry, even if the name becomes available
shortly afterward.

3. Old retries shorten a new Start's window ✓ Resolved
Description
startVectis() posts a retry whose guard checks the current running state, but not whether the
callback belongs to the current Start; stopVectis() leaves that callback queued. If Stop and Start
occur before it fires and the new bind also fails, both the old and new callbacks make attempts
against the same ten-try budget, which can be exhausted before the intended retry window passes.

Grey Divider

Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@compot-dev

Copy link
Copy Markdown
Collaborator Author

Fixed in a6eb1d6:

  1. Fixes lack tests: the link check is now a plain function, MainActivity.linkToOpen(action, data, flags), used by openLink(), with a JVM test (camexLinkUsedOnlyWhenNotFromRecents: a VIEW link opens, the same with FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY does not, nor a non-VIEW intent or one without data). The bind retry depends on the Android socket and the service's main thread; it is covered by the run on the box (below and in the description).
  2. A later Start cannot retry the socket and 3. Old retries shorten a new Start's window: the retry is now one Runnable field (retryBind). A new Start (startVectis()) cancels any pending retry and resets the budget, then binds (bindVectis()); a failed bind replaces the pending retry instead of adding a chain; Stop cancels it and resets the budget.

Build, lint and 24 unit tests pass in the container. On the box: Stop, then Start 5 s later, twice: vectis, the adapter and the tunnel came back each time, no "still taken" or "cannot open the socket" line, the page answers through the camex server's nginx. The Linux mipsel failure was the runner's apt step timing out again.

@compot-dev

Copy link
Copy Markdown
Collaborator Author

/review

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a6eb1d6

@compot-dev
compot-dev merged commit 1d9c7e8 into master Nov 18, 2026
27 of 28 checks passed
@compot-dev
compot-dev deleted the fix/android-socket-101 branch November 18, 2026 04:03
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.

Android: a quick Stop and Start can leave vectis not running (socket name still in use)

1 participant