Skip to content

Android e2e: a peer that serves each connection on its own (#173) - #183

Merged
compot-dev merged 1 commit into
masterfrom
android5-restart-173
Nov 18, 2026
Merged

compot-dev merged 1 commit into
masterfrom
android5-restart-173

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

Closes #173.

The "start() after stop()" failures on the Android 5.0 emulator came from the test's peer, not from Android or the library.

What happened. The peer handled one connection at a time (while true; do echo peer-ok | nc -l -p 9000; done). A connection the app opened just before stop() lost its app side when the VPN was torn down. The peer's nc kept waiting on it (FIN_WAIT1, 9 bytes unsent) for minutes. Meanwhile nothing listened on port 9000, so every new connection got a reset and ECONNREFUSED.

Evidence from a failing run on API 21:

  • A packet capture on the emulator: after start(), the app's new sockets went through tun0 with the tunnel address (10.200.0.3), and the peer answered each SYN with RST.
  • netstat in the peer's container at the same time: no listener on 9000; the only nc held a connection from the app's previous address (10.200.0.4) in FIN_WAIT1.
  • ip rule and all routing tables were identical in passing and failing runs.

The real Android 5.0 part. A connection opened right at CONNECTED may leave through eth0, before the VPN's rules apply. Its retries then reach the tunnel with 10.0.2.15 as source, and the server drops them (the "source address 10.0.2.15" lines in the issue). The next connection goes through the tunnel. The test's askPeer() already retries.

Changes (tests and docs only, no release):

  • tests/android/tunnel-e2e.sh: the peer is nc -lk -p 9000 -e echo peer-ok, a process per connection; the KNOWN (#173) case is gone.
  • TunnelE2eTest: start() after stop() must reach the peer on Android 5.0 too.
  • docs/android-library.md: the Android 5.0 note keeps only the real part.

Tested locally on the emulator (Docker):

  • API 21: 8 of 8 runs pass (6 UDP, 2 TCP), 14/14 checks each. Before the fix, about one run in three failed.
  • API 34: passes, 14/14.

The 'start() after stop()' failures on the Android 5.0 emulator were the
test's peer, not Android. The peer served one connection at a time
(while true; do echo peer-ok | nc -l -p 9000; done). A connection the app
opened just before stop() lost its app side with the VPN; the peer's nc
waited on it (FIN_WAIT1) for minutes, nothing listened on port 9000, and
every new connection got a reset (ECONNREFUSED). A packet capture on the
emulator showed the app's new sockets going through tun0 with the tunnel
address all along, and ip rule and the routes were the same as in passing
runs.

- The peer is 'nc -lk -p 9000 -e echo peer-ok': a process per connection.
- TunnelE2eTest wants the peer after start() after stop() on Android 5.0
  too; the KNOWN case of the script is gone.
- docs/android-library.md: the Android 5.0 note keeps the real part (a
  connection opened right at CONNECTED may leave outside the VPN; a new
  one goes through it).

Closes #173
@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

Make the Android e2e peer serve connections independently

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Serve peer connections independently so abandoned sockets cannot block the restart test.
• Require peer connectivity after stop() and start() on Android 5.0.
• Clarify the remaining Android 5.0 routing delay and its workaround.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 0 capabilities

  • No production behavior changes identified.
Behavioral complexity 🟢 Low 🧩 Assessed behavior

  • No production behavior changes identified.
Potential damage 🟢 Low 🩹 Assessed behavior

  • No production behavior changes identified.
Assessed commit 741491a > Snapshot assessment: the current PR revision could not be verified.
Diagram

graph TD
  Runner["E2E script"] --> Test["Instrumented test"] --> VPN["App VPN"] --> Server["Camex server"] --> Peer["Peer tunnel"] --> Listener["Concurrent listener"]
  Runner --> Listener
Loading
High-Level Assessment

Keep the concurrent listener in the existing peer container: it fixes the fixture's one-connection bottleneck without changing the library or adding a dependency. A separate concurrent server could also work, but adds unnecessary test infrastructure.

Files changed (3) +15 / -36

Bug fix (1) +6 / -10
tunnel-e2e.shServe peer connections independently and fail unreachable restarts +6/-10

Serve peer connections independently and fail unreachable restarts

• Replaces the sequential netcat loop with a persistent listener that runs a response command per connection, preventing an abandoned socket from blocking later connections. Removes the 'KNOWN' outcome so a missing post-restart peer check fails.

tests/android/tunnel-e2e.sh

Tests (1) +2 / -18
TunnelE2eTest.javaRequire restart connectivity on Android 5.0 +2/-18

Require restart connectivity on Android 5.0

• Removes the API 21 exception that logged an unreachable peer without failing. The same peer response assertion now applies after 'stop()' and 'start()' on every tested Android version.

android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java

Documentation (1) +7 / -8
android-library.mdCorrect the Android 5.0 routing guidance +7/-8

Correct the Android 5.0 routing guidance

• Replaces the claimed persistent restart failure with the narrower delay immediately after 'CONNECTED'. Advises timing out an affected connection and opening a new one.

docs/android-library.md

@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 (2) 📘 Rule violations (0) 📎 Requirement gaps (1) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Android 5.0 fix is verified only on an emulator 📎 Requirement gap ≡ Correctness
Description
The PR removes the SDK_INT > 21 branch in TunnelE2eTest.run() that tolerated a missing peer
reply on Android 5.0, so askPeer(peer) must now return "peer-ok" on API 21 within the same
20-attempt budget (3 s connect timeout plus 1 s sleep). The only Android 5.0 evidence is a local
Docker emulator run (8 of 8 on API 21, plus API 34), while the ticket reports TCP failing to recover
within that budget on API 21 (10/14), so the claimed #173 fix is unproven on a real device and the
assertion will fail if the source-address problem persists.
Code

android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java[R218-220]

       await(CamexTunnel.State.CONNECTED, 90);
-        if (android.os.Build.VERSION.SDK_INT > 21) {
-            assertEquals("peer-ok", askPeer(peer));
-            Log.i(TAG, "start after stop OK");
-        } else {
-            // Android 5.0 sometimes routes the app's own sockets outside a VPN made again in
-            // one process (OpenIPC/camex#173): in seconds, or not at all. Recorded, not failed
-            long t0 = android.os.SystemClock.elapsedRealtime();
-            String r = null;
-            while (r == null && android.os.SystemClock.elapsedRealtime() - t0 < 60000) {
-                r = askPeer(peer);
-            }
-            long s = (android.os.SystemClock.elapsedRealtime() - t0) / 1000;
-            if ("peer-ok".equals(r)) {
-                Log.i(TAG, "start after stop OK (after " + s + " s on Android 5.0)");
-            } else {
-                Log.i(TAG, "start after stop: peer not reached in " + s + " s on Android 5.0 (#173)");
-            }
-        }
+        assertEquals("peer-ok", askPeer(peer));
+        Log.i(TAG, "start after stop OK");
Evidence
The new unconditional assertion assertEquals("peer-ok", askPeer(peer)) runs on Android 5.0 and is
the check the PR claims fixes #173. The removed branch documents that Android 5.0 can route the
app's sockets outside the new VPN, and the ticket describes the TCP case failing after about 20
retries. The PR's 'Tested' section lists only 'the emulator (Docker)' for API 21 and API 34, with no
real Android 5 device, and the replacement uses the same askPeer retry budget, so it relies on the
peer fix being the whole story, which the PR does not show for the TCP transport. This violates the
rule that the Stop → Start path must be checked on a real Android 5 device.

Verify Stop → Start behavior in the camex app and on a real Android 5 device
android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java[218-220]
android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java[216-236]
android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java[235-249]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR removes the Android 5.0 tolerance branch in `TunnelE2eTest` and makes the start-after-stop peer check mandatory on API 21, claiming the #173 fix. The only Android 5.0 evidence is a Docker emulator run (8 of 8 on API 21, plus API 34). The ticket reports the TCP transport failing to recover within the 20-attempt `askPeer` budget on API 21 (10/14), so the new assertion will fail if the source-address problem persists. The rule requires checking the camex app's Stop → Start path on a real Android 5 device, since a real-device difference (for example in VPN routing) would otherwise go unseen.
## Fix Focus Areas
- android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java[216-236]
- android/tunnel/src/androidTest/java/org/openipc/camex/tunnel/TunnelE2eTest.java[235-249]
- tests/android/tunnel-e2e.sh[242-245]
## Recommended Fix
Before merge, run the `TunnelE2eTest` start-after-stop scenario on at least one physical Android 5.0 device, with the app's Stop → Start in the same process and the peer on port 9000. Run the TCP transport on API 21 repeatedly (for example 10+ runs) and record the pass/fail result, time to reach the peer, and the source address of new sockets in the PR description or ticket #173. If the TCP case cannot be shown to pass, either restore the Android 5.0 branch that records the outcome and time instead of failing, or extend the budget with a clear documented reason, and make the choice explicit in the test comment. If no device is available, state in the PR that the real-device check is still pending.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Docs state an unverified routing mechanism as fact 🐞 Bug ≡ Correctness
Description
The new Android 5.0 note says the VPN's routing applies a moment after CONNECTED and advises apps to
time out and reopen the connection. The PR's own packet capture says new sockets already use the
tunnel address, so the stated mechanism contradicts the evidence, and the "work as the first start
does" claim is not supported by the ticket's unresolved open questions.
Code

docs/android-library.md[R166-171]

+Android 5.0 may apply the VPN's routing a moment after `CONNECTED`. A
+connection the app opens at that very moment can leave through the device's
+own network, and its retries then reach the tunnel with that network's source
+address, which the server drops. Give such a connection a timeout and open a
+new one: it goes through the tunnel
+([#173](https://github.com/OpenIPC/camex/issues/173)). A `stop()` and a new
Evidence
The PR description says the new sockets went through tun0 with the tunnel address and that the root
cause was the peer, yet the docs attribute the failure to routing applied late after CONNECTED. The
ticket explicitly lists the Android 5.0 route or source-address cache behaviour as an open question,
and the PR does not show a mechanism. Library users reading the doc will build workarounds for a
cause that has not been confirmed.

docs/android-library.md[164-173]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The Android 5.0 note in the library docs states a specific mechanism (VPN routing applied a moment after CONNECTED) and a workaround (timeout and reopen). The PR's own capture shows new sockets using the tunnel address, and the ticket lists the cause as open.
## Fix Focus Areas
- docs/android-library.md[166-171]
## Recommended Fix
State only what is verified: the observed symptom on API 21, that retries from a connection opened at CONNECTED can be dropped, and that a new connection worked in the runs. Remove the claim that a stop() and new start() 'work as the first start does' unless the TCP case is confirmed on API 21. Keep the issue link open until the cause is established.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Closes #173 while the cause on Android 5.0 is unconfirmed 🐞 Bug ⚙ Maintainability
Description
The commit and PR text say Closes #173 and attribute the failure to the test's peer, but the
ticket's open items (route or source-address cache across teardown, a real Android 5 device check,
and the camex app's Stop→Start behaviour) are not addressed. The PR's packet capture also conflicts
with the ticket's server-side drop log, which shows source 10.0.2.15 rather than the tunnel address.
Code

docs/android-library.md[R171-173]

+([#173](https://github.com/OpenIPC/camex/issues/173)). A `stop()` and a new
+`start()` in the same process work as the first start does.
Evidence
The auto-close will hide the open Android 5.0 question from the tracker even though the docs in the
same PR still describe it as a real, unexplained behaviour. The ticket asked for checks on a real
Android 5 device and on the camex app, and the PR does not report either.

docs/android-library.md[166-173]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR uses 'Closes #173' while the Android 5.0 source-address behaviour is still described in the docs as a real effect, and the ticket's open checks are not reported.
## Fix Focus Areas
- docs/android-library.md[166-173]
## Recommended Fix
Replace 'Closes #173' with 'Refs #173' in the commit and PR text, or keep the issue open until a real Android 5 device run and the camex Stop→Start check are reported.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


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 compot-dev added the no-release Changes the build or the code without changing the binaries: no new version, no release label Nov 18, 2026
@compot-dev

Copy link
Copy Markdown
Collaborator Author

Qodo's findings, answered without changes:

  1. Verified only on an emulator. True: there is no Android 5 device in our lab (its Android boxes run Android 10), and Android 5.0: after stop() and start() in one process the app's sockets use eth0's source address in the tunnel #173 itself came from the emulator. But this PR fixes the test, not device behaviour. The failure is explained by evidence from the failing runs: the peer's only nc was stuck on a dead connection in FIN_WAIT1 with no listener on 9000, while the app's new sockets went through tun0 with the tunnel address. The old 20-attempt budget is enough once the peer listens: 8 of 8 runs on API 21 (including 2 over TCP, the transport that failed 10/14 before) and API 34 pass.

  2. Docs state an unverified mechanism. The capture supports it. askPeer() runs only after await(CONNECTED), yet its first socket's SYN left through eth0 with 10.0.2.15. That socket's retransmissions then went into tun0 with the same source, which the server dropped. Every later socket used tun0 with 10.200.0.3. So the routing applied a moment after CONNECTED, and a new connection goes through the tunnel, as the note says.

  3. Closes Android 5.0: after stop() and start() in one process the app's sockets use eth0's source address in the tunnel #173 while the cause is unconfirmed. The server's source address 10.0.2.15 drops in the issue are that first socket's retransmissions (point 2), so they agree with the capture. The open items: a route or source-address cache across the teardown is ruled out (ip rule and all routing tables are identical in passing and failing runs, and new sockets use the tunnel address). The "no answer for minutes" part was the test's peer. A real Android 5 device is not available; the camex app uses the same library.

@compot-dev
compot-dev merged commit 4dcc8cc into master Nov 18, 2026
33 of 37 checks passed
@compot-dev
compot-dev deleted the android5-restart-173 branch November 18, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-release Changes the build or the code without changing the binaries: no new version, no release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android 5.0: after stop() and start() in one process the app's sockets use eth0's source address in the tunnel

1 participant