<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KlarVPN</title>
    <description>The latest articles on DEV Community by KlarVPN (@klarvpn).</description>
    <link>https://dev.to/klarvpn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3381849%2F4a12d928-7f9a-4b9b-b6f1-442af1b3a468.png</url>
      <title>DEV Community: KlarVPN</title>
      <link>https://dev.to/klarvpn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/klarvpn"/>
    <language>en</language>
    <item>
      <title>My WebSocket Reconnected After a Free VPN Switch. Where Did Messages 42–47 Go?</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Tue, 24 Nov 2026 11:13:49 +0000</pubDate>
      <link>https://dev.to/klarvpn/my-websocket-reconnected-after-a-free-vpn-switch-where-did-messages-42-47-go-196n</link>
      <guid>https://dev.to/klarvpn/my-websocket-reconnected-after-a-free-vpn-switch-where-did-messages-42-47-go-196n</guid>
      <description>&lt;p&gt;Your dashboard receives event &lt;code&gt;41&lt;/code&gt;. You switch locations in a free VPN, the WebSocket drops, and a moment later the connection indicator turns green again. The next event on screen is &lt;code&gt;48&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Where did &lt;code&gt;42&lt;/code&gt; through &lt;code&gt;47&lt;/code&gt; go?&lt;/p&gt;

&lt;p&gt;They may never have been sent to this client. The server could have produced all six while the dashboard was disconnected, then registered the new connection just in time for &lt;code&gt;48&lt;/code&gt;. From the server’s perspective, the new socket is healthy. From the user’s perspective, six updates are missing.&lt;/p&gt;

&lt;p&gt;That distinction matters if the feed carries changes rather than snapshots. If every message contains the current temperature, the latest reading might be enough. If each message adds an item to an order, skipping six events leaves the order wrong even as new updates arrive.&lt;/p&gt;

&lt;p&gt;Let’s reproduce the gap, then recover from it. The test uses a JavaScript client, a small local WebSocket server, and a deliberate duplicate that catches a common mistake in reconnect logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the failure repeatable
&lt;/h2&gt;

&lt;p&gt;A VPN switch is a useful real-world way to exercise a remote connection, but it makes a poor first test. The socket might survive, the interruption might last half a second, or no events might arrive during it. And switching VPN locations usually won’t interrupt a loopback connection on your laptop.&lt;/p&gt;

&lt;p&gt;Instead, our server will give every run the same history:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The client starts with event &lt;code&gt;40&lt;/code&gt; already applied.&lt;/li&gt;
&lt;li&gt;The server sends &lt;code&gt;41&lt;/code&gt; and ends the first session.&lt;/li&gt;
&lt;li&gt;Events &lt;code&gt;42&lt;/code&gt; through &lt;code&gt;47&lt;/code&gt; are available in the server’s history. The first session never receives them.&lt;/li&gt;
&lt;li&gt;The client reconnects. It can subscribe to new events or ask for the ones it missed.&lt;/li&gt;
&lt;li&gt;The next live event is &lt;code&gt;48&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The sequence numbers are consecutive &lt;strong&gt;within this one feed&lt;/strong&gt;. That detail matters later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start the demo server
&lt;/h2&gt;

&lt;p&gt;You’ll need Python 3.10 or newer and Node.js 22 or newer. In a project directory, set up the server dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 -m venv .venv
&lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate
python -m pip install &lt;span class="nv"&gt;websockets&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;16.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this as &lt;code&gt;feed.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;websockets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;serve&lt;/span&gt;

&lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;recv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"41"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"resume:"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;":"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Deliver the last replayed event twice to exercise the client.&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"48"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8765&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start it with &lt;code&gt;python feed.py&lt;/code&gt; and leave that terminal open. This is a single-client fixture: each &lt;code&gt;start&lt;/code&gt; resets the history, and each run ends at &lt;code&gt;48&lt;/code&gt;. That gives us a known result to check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the client one rule about progress
&lt;/h2&gt;

&lt;p&gt;The most important variable is &lt;code&gt;lastApplied&lt;/code&gt;. It records the last consecutive event the client &lt;strong&gt;successfully handled&lt;/strong&gt;. If the client sees &lt;code&gt;48&lt;/code&gt; while expecting &lt;code&gt;42&lt;/code&gt;, moving that variable to &lt;code&gt;48&lt;/code&gt; would turn a recoverable gap into six silently skipped events. The next resume request would ask for everything &lt;em&gt;after&lt;/em&gt; &lt;code&gt;48&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Save this as &lt;code&gt;client.mjs&lt;/code&gt;. It uses the WebSocket client built into Node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;replay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'resume'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;lastApplied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ws://127.0.0.1:8765'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onopen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onerror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'WebSocket connection failed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onclose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onmessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;lastApplied&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'duplicate'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="n"&gt;lastApplied&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'gap: expected'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lastApplied&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'received'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'applied'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;lastApplied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'start'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replay&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'resume:'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;lastApplied&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'live'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'last applied:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lastApplied&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, applying an event means printing it. In an order dashboard, that line might update a quantity or insert a row. The checkpoint belongs &lt;strong&gt;after&lt;/strong&gt; that operation succeeds. If your handler writes asynchronously, process this ordered feed through a single queue so a later handler can’t advance the checkpoint while an earlier write is still pending.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it once without replay
&lt;/h2&gt;

&lt;p&gt;In a second terminal, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node client.mjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is short enough to see the bug:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;applied 41
gap: expected 42 received 48
last applied: 41
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second WebSocket opened successfully. We know because it received &lt;code&gt;48&lt;/code&gt;. A UI that changes its badge to “Up to date” inside &lt;code&gt;onopen&lt;/code&gt; would show the wrong state at precisely this moment.&lt;/p&gt;

&lt;p&gt;Notice what the client did right even in the failing run: it left the checkpoint at &lt;code&gt;41&lt;/code&gt;. It can still ask for the missing history. Simply adding &lt;code&gt;socket.connect()&lt;/code&gt; retries would never answer the question of which events the next connection should receive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconnect with a checkpoint
&lt;/h2&gt;

&lt;p&gt;Now run the same client in resume mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node client.mjs resume
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time the second connection sends &lt;code&gt;resume:41&lt;/code&gt;. The output becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;applied 41
applied 42
applied 43
applied 44
applied 45
applied 46
applied 47
duplicate 47
applied 48
last applied: 48
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two separate wins here. The server can replay &lt;code&gt;42&lt;/code&gt; through &lt;code&gt;47&lt;/code&gt; because it retained them. And when &lt;code&gt;47&lt;/code&gt; arrives again, the client recognizes that it has already applied it. If &lt;code&gt;47&lt;/code&gt; meant “add one item,” the cart would gain one item rather than two.&lt;/p&gt;

&lt;p&gt;The duplicate is deliberate. In a real system, ambiguity can arise when a client handles an event and the connection dies before its acknowledgment reaches the server. Replaying that event is reasonable. A stable event ID gives the client a way to recognize it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Close the gap between replay and live delivery
&lt;/h2&gt;

&lt;p&gt;There’s one shortcut in the demo that deserves attention: &lt;code&gt;48&lt;/code&gt; always comes after replay. A production server doesn’t stop receiving writes while one client catches up.&lt;/p&gt;

&lt;p&gt;Consider what happens if the server reads history through &lt;code&gt;47&lt;/code&gt;, spends a moment sending it, and only then subscribes the client to live events. If &lt;code&gt;48&lt;/code&gt; was published in that interval, you’ve recreated the original bug inside the recovery code.&lt;/p&gt;

&lt;p&gt;One design is to consume both historical and new events from the same ordered, durable log, starting just after the client’s checkpoint. If history and live delivery are separate, the handoff needs an explicit boundary. For example, register a live subscription that buffers events first, capture the current log position, replay through that position, then drain newer buffered events in order. That design depends on the live subscription and history sharing the same event positions.&lt;/p&gt;

&lt;p&gt;Two details are worth deciding before shipping:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What if the checkpoint has expired?&lt;/strong&gt; If the client asks for events after &lt;code&gt;41&lt;/code&gt; and the oldest retained event is &lt;code&gt;80&lt;/code&gt;, respond explicitly that it needs a fresh snapshot. Give the snapshot a matching log position so the client knows where to resume.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What if IDs legitimately skip?&lt;/strong&gt; This demo can treat &lt;code&gt;41 → 48&lt;/code&gt; as a gap because its feed promises consecutive IDs. A filtered feed using global database IDs might naturally jump from &lt;code&gt;41&lt;/code&gt; to &lt;code&gt;48&lt;/code&gt;. For that feed, use a server-issued cursor or a per-stream sequence. Otherwise, the client will report missing messages that never belonged to it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the client persists its state across restarts, persist the checkpoint consistently with the state it represents. Saving &lt;code&gt;lastApplied = 47&lt;/code&gt; before saving the effect of event &lt;code&gt;47&lt;/code&gt; can make that update disappear permanently after a crash.&lt;/p&gt;

&lt;h2&gt;
  
  
  Take the test back to the VPN
&lt;/h2&gt;

&lt;p&gt;Once the local test passes, try the same observation against a remote development feed you control. Keep events flowing, record the last applied ID, switch VPN locations, and note whether the socket actually closes. An &lt;a href="https://www.klarvpn.com/blog/how-to-check-if-vpn-is-working" rel="noopener noreferrer"&gt;&lt;strong&gt;on/off public IP check&lt;/strong&gt;&lt;/a&gt; can help confirm that the client’s outward-facing address changed. The event log answers the separate question of whether the feed recovered.&lt;/p&gt;

&lt;p&gt;For the UI, give “Connected” and “Up to date” different meanings. The socket can report “Connected” as soon as it opens. The feed can report “Up to date” once it has applied replay through a known server position and completed the handoff to live updates.&lt;/p&gt;

&lt;p&gt;That gives you a better acceptance test than watching the badge turn green: &lt;strong&gt;disconnect after &lt;code&gt;41&lt;/code&gt;, produce six events, reconnect, deliver &lt;code&gt;47&lt;/code&gt; twice, and confirm the client applies every event through &lt;code&gt;48&lt;/code&gt; exactly once in that run.&lt;/strong&gt; Now the badge has evidence behind it.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>vpn</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Why Can’t My Android Phone Reach My Local API When a Free VPN Is On?</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Fri, 20 Nov 2026 13:20:53 +0000</pubDate>
      <link>https://dev.to/klarvpn/why-cant-my-android-phone-reach-my-local-api-when-a-free-vpn-is-on-24j</link>
      <guid>https://dev.to/klarvpn/why-cant-my-android-phone-reach-my-local-api-when-a-free-vpn-is-on-24j</guid>
      <description>&lt;p&gt;Your API returns &lt;code&gt;200 OK&lt;/code&gt; on your laptop. You open the same endpoint from your Android phone with a free VPN connected, and the request hangs. Meanwhile, the phone can browse the web just fine.&lt;/p&gt;

&lt;p&gt;Before you change your app’s base URL or start editing firewall rules, watch the terminal where the API is running. &lt;strong&gt;Does a &lt;code&gt;GET /health&lt;/code&gt; line appear when you refresh the page on the phone?&lt;/strong&gt; That one observation tells you whether to investigate how the request reaches the laptop or what happens after it arrives.&lt;/p&gt;

&lt;p&gt;Here’s a small experiment you can run on your own Wi-Fi. You’ll use one endpoint, one physical Android phone, and two network paths. The second path, over USB, also gives you a way to keep developing if Wi-Fi is still giving you trouble.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the phone something recognizable to request
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;health.cjs&lt;/code&gt; on your laptop. It uses Node.js without any dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'node:http'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'GET'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'/health'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'Cache-Control'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'no-store'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'laptop-api'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'0.0.0.0'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;node health.cjs&lt;/code&gt;. In a second terminal, check the endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i http://127.0.0.1:3000/health
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for &lt;code&gt;200 OK&lt;/code&gt;, the service name &lt;code&gt;laptop-api&lt;/code&gt;, and a fresh &lt;code&gt;GET /health&lt;/code&gt; in the server terminal. The changing &lt;code&gt;time&lt;/code&gt; value gives you a way to recognize a fresh response on the phone, too.&lt;/p&gt;

&lt;p&gt;The address in &lt;code&gt;listen()&lt;/code&gt; matters. Binding to &lt;code&gt;127.0.0.1&lt;/code&gt; would let this laptop test pass while preventing a direct connection from another device. &lt;code&gt;0.0.0.0&lt;/code&gt; tells Node to listen on all the laptop’s IPv4 interfaces, including Wi-Fi. Use this temporary server on a network you control and stop it with &lt;code&gt;Ctrl+C&lt;/code&gt; when you’re done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Establish the Wi-Fi baseline
&lt;/h2&gt;

&lt;p&gt;Find the IPv4 address listed for the laptop’s active Wi-Fi connection. Suppose it’s &lt;code&gt;192.168.1.42&lt;/code&gt;. On the laptop, try the LAN address before picking up the phone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i http://192.168.1.42:3000/health
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the example address with yours. If this request fails while &lt;code&gt;127.0.0.1&lt;/code&gt; works, fix the address or listener first. On a machine with Docker, a VPN, and Wi-Fi running together, it’s easy to copy an address from the wrong interface.&lt;/p&gt;

&lt;p&gt;Now connect the &lt;strong&gt;physical phone&lt;/strong&gt; to the same trusted Wi-Fi network. With the phone’s VPN disconnected, enter &lt;code&gt;http://192.168.1.42:3000/health&lt;/code&gt; in its browser, again substituting the laptop’s address. Include &lt;code&gt;http://&lt;/code&gt; because the sample server speaks plain HTTP.&lt;/p&gt;

&lt;p&gt;Three details can save you a surprising amount of debugging:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;localhost&lt;/code&gt; on the phone means the phone itself. It will become useful in the USB test below.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;10.0.2.2&lt;/code&gt; is a special address the Android Emulator uses to reach its host. A physical phone on Wi-Fi needs the laptop’s LAN address.&lt;/li&gt;
&lt;li&gt;A successful request from the laptop to its own LAN address checks the address and listener. The phone’s request is the one that tests incoming traffic from another device.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Record whether the phone displays &lt;code&gt;laptop-api&lt;/code&gt; and whether the server logs &lt;code&gt;GET /health&lt;/code&gt;. Ignore incidental browser requests such as &lt;code&gt;GET /favicon.ico&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change one thing: connect the VPN on the phone
&lt;/h2&gt;

&lt;p&gt;Leave the server running. Keep the same phone, browser tab, Wi-Fi network, port, and numeric IP address. Connect the VPN &lt;strong&gt;on the phone&lt;/strong&gt;, wait until it reports connected, then refresh. If the page loads, check that the &lt;code&gt;time&lt;/code&gt; value changes.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;VPN off&lt;/th&gt;
&lt;th&gt;VPN on&lt;/th&gt;
&lt;th&gt;What to investigate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Loads&lt;/td&gt;
&lt;td&gt;Times out&lt;/td&gt;
&lt;td&gt;If only the first request appears in the server log, inspect the VPN’s handling of local network traffic.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Times out&lt;/td&gt;
&lt;td&gt;Times out&lt;/td&gt;
&lt;td&gt;Start with the LAN address, laptop firewall, and Wi-Fi client isolation. The baseline already fails.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Loads&lt;/td&gt;
&lt;td&gt;Loads&lt;/td&gt;
&lt;td&gt;The browser can reach this endpoint in both states. If the app still fails, inspect the app’s request.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Times out&lt;/td&gt;
&lt;td&gt;Loads&lt;/td&gt;
&lt;td&gt;Repeat in reverse order and check the log timestamps. Confirm the phone stayed on the same Wi-Fi and used the same address.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A repeatable off/on/off result is more informative than one timeout. If the first and third requests arrive and the middle one never appears, you have a specific question to investigate: &lt;strong&gt;what happens to traffic addressed to the laptop’s private IP while this VPN configuration is active?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Look in the VPN client for a setting concerning local network or LAN access. If your setup permits changing it, change only that setting and repeat the request with the VPN connected. The word &lt;em&gt;free&lt;/em&gt; describes the plan. It doesn’t tell you how the client handles a local destination.&lt;/p&gt;

&lt;p&gt;There’s also a useful distinction between &lt;a href="https://www.klarvpn.com/blog/do-you-need-a-vpn-on-android" rel="noopener noreferrer"&gt;&lt;strong&gt;Android Private DNS and a VPN connection&lt;/strong&gt;&lt;/a&gt;. This test uses a numeric IP, so the browser has no laptop hostname to resolve. If the numeric address works but your usual development hostname fails, you’ve found a reason to investigate name resolution separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let the server log decide the next step
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;No request reaches the server, even with the VPN off.&lt;/strong&gt; Check whether the phone is on a guest network. Two devices can have internet access from the same Wi-Fi network while the access point prevents them from reaching each other. Also check whether the laptop firewall permits incoming TCP connections to port &lt;code&gt;3000&lt;/code&gt; on your development network. There’s no need to disable the entire firewall to test one port.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The server logs &lt;code&gt;GET /health&lt;/code&gt;, but the phone shows an error.&lt;/strong&gt; The request reached the Node process. Record the browser’s exact error and inspect the response. A line in the server log establishes arrival, but it can’t tell you whether the phone received and accepted the complete response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The phone’s browser works, but your app fails.&lt;/strong&gt; Compare the app’s actual scheme, host, port, and path with the working browser address. Check Logcat for the first underlying error. For example, &lt;code&gt;CLEARTEXT communication ... not permitted&lt;/code&gt; points to the app’s HTTP policy. Changing VPN settings won’t make an HTTP endpoint satisfy an HTTPS requirement. Use an appropriate development HTTPS endpoint or a debug-only policy scoped to your test setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use USB to keep working
&lt;/h2&gt;

&lt;p&gt;If your immediate goal is to test an app feature against the laptop API, Android’s &lt;code&gt;adb reverse&lt;/code&gt; gives you another path. With a USB mapping in place, a connection to a port on the phone can reach a port on the laptop. You can leave the phone’s VPN connected for this comparison.&lt;/p&gt;

&lt;p&gt;With Android SDK Platform-Tools installed, enable USB debugging on the phone, connect it using a data-capable cable, and approve the debugging prompt for your development machine. Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adb devices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once your phone appears with the state &lt;code&gt;device&lt;/code&gt;, create the mapping. These commands assume it’s the only connected Android target.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adb reverse tcp:3000 tcp:3000
adb reverse --list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now open &lt;strong&gt;&lt;code&gt;http://127.0.0.1:3000/health&lt;/code&gt; on the phone&lt;/strong&gt;. This is the point where using loopback becomes intentional. ADB listens on device port &lt;code&gt;3000&lt;/code&gt; and forwards the connection to port &lt;code&gt;3000&lt;/code&gt; on the development machine.&lt;/p&gt;

&lt;p&gt;If you see &lt;code&gt;laptop-api&lt;/code&gt; with a fresh timestamp, you can use that address in your app’s debug configuration, subject to the app’s HTTP policy. A successful USB request shows the phone can reach the service over ADB. The original Wi-Fi route is still a separate question.&lt;/p&gt;

&lt;p&gt;When you finish, remove the mapping:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adb reverse --remove tcp:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most useful bug report from this exercise is only a few lines long. Record the &lt;strong&gt;address the phone requested&lt;/strong&gt;, &lt;strong&gt;whether the VPN was connected&lt;/strong&gt;, &lt;strong&gt;whether the server logged the request&lt;/strong&gt;, and &lt;strong&gt;whether USB worked&lt;/strong&gt;. “Wi-Fi succeeds with the VPN off, no request arrives with it on, and USB succeeds in both states” gives the next developer a precise place to start.&lt;/p&gt;

</description>
      <category>android</category>
      <category>networking</category>
      <category>webdev</category>
      <category>vpn</category>
    </item>
    <item>
      <title>The Upload Succeeded. Why Did WorkManager Send It Again?</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Wed, 18 Nov 2026 11:50:45 +0000</pubDate>
      <link>https://dev.to/klarvpn/the-upload-succeeded-why-did-workmanager-send-it-again-4fep</link>
      <guid>https://dev.to/klarvpn/the-upload-succeeded-why-did-workmanager-send-it-again-4fep</guid>
      <description>&lt;p&gt;An Android app starts uploading a photo. The server saves it. Before the app receives the response, the connection drops during a VPN reconnect.&lt;/p&gt;

&lt;p&gt;WorkManager runs the upload again. Now the server has two copies.&lt;/p&gt;

&lt;p&gt;From the worker’s perspective, the first attempt ended with a network error. From the server’s perspective, it succeeded. The app has to handle the possibility that both are true.&lt;/p&gt;

&lt;p&gt;The fix starts with one rule: &lt;strong&gt;give each logical upload a stable ID, reuse it on every attempt, and have the server enforce uniqueness.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What WorkManager can tell you
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;NetworkType.CONNECTED&lt;/code&gt; constraint lets WorkManager schedule the job when Android reports connectivity that meets the constraint. If the constraint stops being met while the job runs, WorkManager can stop the worker and run it later. Your own &lt;code&gt;Result.retry()&lt;/code&gt; can also schedule another attempt, with backoff.&lt;/p&gt;

&lt;p&gt;Neither event tells you what the server did with the previous request. A timeout can happen before the server receives the file, partway through the transfer, or after the server commits the upload. Even if the VPN reconnects quickly enough that the network constraint stays satisfied, the existing HTTP connection can still fail.&lt;/p&gt;

&lt;p&gt;That gap is where duplicates happen. Backoff helps control how often you retry. The upload ID makes retrying safe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the upload ID when the user queues the file
&lt;/h2&gt;

&lt;p&gt;Generate a UUID when the user initiates an upload. Save it alongside the account and a reference to a staged copy of the file. Keep the staged bytes unchanged while the upload is pending.&lt;/p&gt;

&lt;p&gt;If the worker runs again after a timeout or process restart, it reads the same record. If the user taps &lt;strong&gt;Retry&lt;/strong&gt; in your app, enqueue work for that record again. Generate a new ID when the user starts a different upload, even if they choose the same file.&lt;/p&gt;

&lt;p&gt;This example sends the file using &lt;code&gt;PUT /uploads/{uploadId}&lt;/code&gt;. The client chooses the resource ID. The server uses the authenticated account and that ID to decide whether it has already accepted the upload.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the Kotlin worker focused on one attempt
&lt;/h2&gt;

&lt;p&gt;The example assumes your app supplies two dependencies through a &lt;code&gt;WorkerFactory&lt;/code&gt;: a local store for pending uploads and a cancellable HTTP client. &lt;code&gt;UploadApi.put()&lt;/code&gt; returns the raw HTTP status, authenticates as the account that queued the upload, and throws &lt;code&gt;IOException&lt;/code&gt; for transport failures. The server returns &lt;code&gt;201&lt;/code&gt; for the initial commit and &lt;code&gt;200&lt;/code&gt; for a replay of the same upload.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;android&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Context&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CoroutineWorker&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WorkerParameters&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;workDataOf&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IOException&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PendingUpload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;accountId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;UploadStore&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PendingUpload&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;UploadApi&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PendingUpload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UploadWorker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;WorkerParameters&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UploadStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UploadApi&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;CoroutineWorker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;doWork&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;inputData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"uploadId"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;workDataOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"reason"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s2"&gt;"missing_id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;upload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;workDataOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"reason"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s2"&gt;"missing_upload"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IOException&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;retryOrReportUnconfirmed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;201&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="mi"&gt;408&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;502&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;504&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;retryOrReportUnconfirmed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;workDataOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"httpStatus"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;retryOrReportUnconfirmed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;runAttemptCount&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;workDataOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"reason"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s2"&gt;"upload_unconfirmed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The worker lets coroutine cancellation propagate. The HTTP client should cancel its in-flight call when the coroutine is cancelled. The status list is an example for this endpoint. An API that returns &lt;code&gt;429&lt;/code&gt; with &lt;code&gt;Retry-After&lt;/code&gt; needs a policy that honors the server’s delay.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;upload_unconfirmed&lt;/code&gt; matters too. Reaching the retry limit means the app still lacks confirmation. It should keep the upload ID so it can check the server’s record or let the user retry the same upload later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use unique work to avoid duplicate jobs on the device
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BackoffPolicy&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Constraints&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ExistingWorkPolicy&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NetworkType&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OneTimeWorkRequestBuilder&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WorkManager&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;workDataOf&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TimeUnit&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;enqueueUpload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;workManager&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;WorkManager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;uploadId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OneTimeWorkRequestBuilder&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UploadWorker&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setInputData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;workDataOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"uploadId"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;uploadId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setConstraints&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;Constraints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setRequiredNetworkType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NetworkType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CONNECTED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setBackoffCriteria&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;BackoffPolicy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EXPONENTIAL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TimeUnit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SECONDS&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;workManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueueUniqueWork&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"upload:$uploadId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;ExistingWorkPolicy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;KEEP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;KEEP&lt;/code&gt; avoids enqueuing another unfinished job with the same name. A single job can still make multiple HTTP attempts. The server must recognize those attempts as belonging to the same upload, even if they arrive close together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enforce uniqueness where the file is committed
&lt;/h2&gt;

&lt;p&gt;For a small-file test endpoint, you can store the bytes and metadata in the same PostgreSQL row. That makes the database commit the point at which the upload becomes durable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;uploads&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;account_id&lt;/span&gt; &lt;span class="kt"&gt;uuid&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;upload_id&lt;/span&gt; &lt;span class="kt"&gt;uuid&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;content_sha256&lt;/span&gt; &lt;span class="kt"&gt;bytea&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="kt"&gt;bytea&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;upload_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;uploads&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;upload_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content_sha256&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;CONFLICT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;upload_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;NOTHING&lt;/span&gt;
&lt;span class="k"&gt;RETURNING&lt;/span&gt; &lt;span class="n"&gt;upload_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compute the hash on the server from the received bytes. If the insert returns a row, commit the transaction before sending &lt;code&gt;201&lt;/code&gt;. If it returns zero rows, read the existing row for that account and upload ID in a separate statement under PostgreSQL’s default &lt;code&gt;READ COMMITTED&lt;/code&gt; isolation. Return &lt;code&gt;200&lt;/code&gt; if the hash matches, or &lt;code&gt;409&lt;/code&gt; if the ID was reused for different content.&lt;/p&gt;

&lt;p&gt;The unique constraint handles two attempts arriving at nearly the same time. A backend that only checks for an existing row before inserting leaves a gap in which both attempts can see no row and proceed.&lt;/p&gt;

&lt;p&gt;If you use object storage, the database constraint protects the row. Give the object write its own idempotent behavior, such as a stable object key with a conditional create, and make sure a retry can reconcile an object saved before the database update.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the failure that creates the duplicate
&lt;/h2&gt;

&lt;p&gt;Start with a controlled test. On a staging endpoint you own, commit the file and then deliberately close the first response before the client can receive it. On the next attempt, let the endpoint respond normally.&lt;/p&gt;

&lt;p&gt;Check three things in the client and server logs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Check&lt;/th&gt;
&lt;th&gt;Expected result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Upload ID on the first and second requests&lt;/td&gt;
&lt;td&gt;Both requests use the same ID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server records for that account and ID&lt;/td&gt;
&lt;td&gt;One committed upload&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Worker result after the replay&lt;/td&gt;
&lt;td&gt;Success after the server acknowledges the existing upload&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Also try reusing the ID with different bytes. The server should return &lt;code&gt;409&lt;/code&gt; and keep the original file.&lt;/p&gt;

&lt;p&gt;For a physical-device check, use the same staging endpoint and a &lt;a href="https://www.klarvpn.com/download/vpn-for-android" rel="noopener noreferrer"&gt;&lt;strong&gt;VPN for Android&lt;/strong&gt;&lt;/a&gt;. Try a reconnect during an upload and see whether the request fails, completes, or gets retried. The outcome can vary with timing. The staging test is how you reliably exercise the case where the server committed the file and the client lost the response.&lt;/p&gt;

&lt;p&gt;If you currently generate a new upload ID inside &lt;code&gt;doWork()&lt;/code&gt;, start there. Move ID creation to the point where the user queues the file, then run the lost-response test. You should be able to see two requests in the logs and one upload on the server.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>vpn</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Your iOS App Says “Offline”—But Is It? Debugging API Failures With a VPN Enabled</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Mon, 16 Nov 2026 13:06:37 +0000</pubDate>
      <link>https://dev.to/klarvpn/your-ios-app-says-offline-but-is-it-debugging-api-failures-with-a-vpn-enabled-358o</link>
      <guid>https://dev.to/klarvpn/your-ios-app-says-offline-but-is-it-debugging-api-failures-with-a-vpn-enabled-358o</guid>
      <description>&lt;p&gt;A user connects their iPhone to a VPN, opens your app and sees:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No internet connection. Please try again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;They switch to another app, which works.&lt;/p&gt;

&lt;p&gt;Your app may have encountered a real failure. But “no internet” might be the wrong diagnosis.&lt;/p&gt;

&lt;p&gt;A hostname lookup can fail. A secure connection can fail. An API can return an authentication error. The response can arrive successfully and then fail JSON decoding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A failed API operation does not automatically mean the device is offline—or that the VPN caused the failure.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first useful fix is to preserve those distinctions in your networking code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with what actually failed
&lt;/h2&gt;

&lt;p&gt;Think of an API operation as several stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Establish a usable network connection.&lt;/li&gt;
&lt;li&gt;Resolve the destination hostname when needed.&lt;/li&gt;
&lt;li&gt;Establish the secure connection.&lt;/li&gt;
&lt;li&gt;Exchange the HTTP request and response.&lt;/li&gt;
&lt;li&gt;Interpret the response body.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is a debugging model, not a claim that every request creates a new connection or performs a fresh DNS lookup. Connections and lookup results can be reused.&lt;/p&gt;

&lt;p&gt;The point is that failures at different stages need different handling.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observation&lt;/th&gt;
&lt;th&gt;What to investigate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;notConnectedToInternet&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Connectivity available to this request and applicable network restrictions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cannotFindHost&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hostname spelling, DNS configuration and resolution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cannotConnectToHost&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Connection establishment, destination availability and routing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;secureConnectionFailed&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;TLS negotiation and trust-related diagnostics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;An HTTP response outside the expected range&lt;/td&gt;
&lt;td&gt;API behavior, authentication, policy or server errors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A decoding error after an accepted response&lt;/td&gt;
&lt;td&gt;Response format and the app’s data model&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An error category narrows the investigation. It rarely identifies the root cause by itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep HTTP failures separate from transport failures
&lt;/h2&gt;

&lt;p&gt;One common mistake is assuming that &lt;code&gt;URLSession&lt;/code&gt; throws whenever the server returns an error status.&lt;/p&gt;

&lt;p&gt;A completed HTTP exchange can return a &lt;code&gt;401&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt; or &lt;code&gt;503&lt;/code&gt; without producing a transport error. Your application needs to inspect the response status.&lt;/p&gt;

&lt;p&gt;Here is a small Swift example for iOS 15 and later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Foundation&lt;/span&gt;

&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;APIError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;nonHTTPResponse&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nf"&gt;httpStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;fetchJSON&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Decodable&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;URLRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;URLSession&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Value&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;guard&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;httpResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;HTTPURLResponse&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;APIError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nonHTTPResponse&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;guard&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;APIError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;httpStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;httpResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="nc"&gt;JSONDecoder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps three useful outcomes distinct:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;URLSession&lt;/code&gt; throws a transport-related error.&lt;/li&gt;
&lt;li&gt;The application rejects an HTTP status.&lt;/li&gt;
&lt;li&gt;The decoder rejects the response body.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The function assumes that an accepted response contains JSON matching &lt;code&gt;Value&lt;/code&gt;. Adapt it for endpoints that legitimately return an empty body, such as a &lt;code&gt;204&lt;/code&gt; response.&lt;/p&gt;

&lt;p&gt;A production client may also decode structured API errors. Avoid discarding those details if they explain what the user needs to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Map errors to messages without inventing a cause
&lt;/h2&gt;

&lt;p&gt;You can turn those categories into clearer interface messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;CancellationError&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;urlError&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;URLError&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;urlError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notConnectedToInternet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"A network connection is unavailable for this request."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cannotFindHost&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dnsLookupFailed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The service address could not be resolved."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cannotConnectToHost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The app could not connect to the service."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;secureConnectionFailed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;serverCertificateHasBadDate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;serverCertificateUntrusted&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;serverCertificateHasUnknownRoot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;serverCertificateNotYetValid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"A secure connection to the service could not be established."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timedOut&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The request took too long. Please try again."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;networkConnectionLost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The connection was interrupted."&lt;/span&gt;

        &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The request could not be completed."&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;apiError&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;APIError&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;apiError&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;httpStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Your session could not be verified. Please sign in again."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;httpStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The service did not allow this request."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;httpStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Too many requests. Please wait before trying again."&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;httpStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The service could not complete the request."&lt;/span&gt;

        &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The service returned an unexpected response."&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;DecodingError&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"The app could not read the service response."&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Something went wrong. Please try again."&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Treat this as a starting point for your app’s language and API contract.&lt;/p&gt;

&lt;p&gt;For example, a &lt;code&gt;401&lt;/code&gt; may trigger a supported token-refresh flow before a sign-in prompt. A &lt;code&gt;403&lt;/code&gt; should not automatically become “Your VPN is blocked.”&lt;/p&gt;

&lt;p&gt;Apple also notes that hostname lookup failures should generally be handled through &lt;code&gt;cannotFindHost&lt;/code&gt;; do not depend on receiving &lt;code&gt;dnsLookupFailed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Keep the original error for diagnostics. A friendly message should not replace the evidence needed to investigate it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use network monitoring as context
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;NWPathMonitor&lt;/code&gt; can help your app observe changes in the available network path.&lt;/p&gt;

&lt;p&gt;It cannot tell you whether your API will authenticate the user, whether the server will return valid JSON or whether a particular request will finish successfully.&lt;/p&gt;

&lt;p&gt;Apple describes a satisfied path as available for establishing connections and sending data. That is useful context, not an end-to-end API health check.&lt;/p&gt;

&lt;p&gt;Avoid reducing your app’s state to a single Boolean named &lt;code&gt;isOnline&lt;/code&gt; and treating it as a guarantee.&lt;/p&gt;

&lt;p&gt;Instead, keep separate observations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The network path appears available.&lt;/li&gt;
&lt;li&gt;The latest request succeeded or failed.&lt;/li&gt;
&lt;li&gt;The service returned a particular HTTP status.&lt;/li&gt;
&lt;li&gt;The response could or could not be decoded.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your interface can then say “Couldn’t refresh your account” while continuing to show previously loaded data, rather than incorrectly declaring the entire phone offline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare VPN conditions without guessing
&lt;/h2&gt;

&lt;p&gt;Use a physical device, a test account and a harmless endpoint you control. Record the iOS version, app build, network type and VPN configuration.&lt;/p&gt;

&lt;p&gt;When including a &lt;a href="https://www.klarvpn.com/download/vpn-for-iphone" rel="noopener noreferrer"&gt;&lt;strong&gt;VPN for iPhone&lt;/strong&gt;&lt;/a&gt; in the test setup, document the conditions under which each request runs. The connected indicator alone does not explain an API failure.&lt;/p&gt;

&lt;p&gt;A useful comparison includes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test condition&lt;/th&gt;
&lt;th&gt;Record&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Stable connection without the VPN&lt;/td&gt;
&lt;td&gt;Baseline response or error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same network with the VPN connected&lt;/td&gt;
&lt;td&gt;Whether the outcome changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Request during a VPN reconnect&lt;/td&gt;
&lt;td&gt;Error category and timing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Wi-Fi-to-cellular transition&lt;/td&gt;
&lt;td&gt;Whether the request completes or fails&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deliberately returned test HTTP error&lt;/td&gt;
&lt;td&gt;Whether the interface shows the correct message&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deliberately malformed test JSON&lt;/td&gt;
&lt;td&gt;Whether decoding failure stays distinct from connectivity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Use the same endpoint and request parameters where possible. Repeat observations before attributing a difference to the VPN.&lt;/p&gt;

&lt;p&gt;For a network comparison, use a non-cached test response so that locally stored data does not look like a successful live request.&lt;/p&gt;

&lt;p&gt;A result that occurs only with the VPN enabled is a lead. It is not yet a diagnosis. Resolver behavior, routing, destination-side policies and timing may need separate investigation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Log enough to connect the client and server evidence
&lt;/h2&gt;

&lt;p&gt;Useful diagnostic fields include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Timestamp and elapsed duration.&lt;/li&gt;
&lt;li&gt;App and operating-system versions.&lt;/li&gt;
&lt;li&gt;A safe operation name, such as &lt;code&gt;loadProfile&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Error domain and numeric code.&lt;/li&gt;
&lt;li&gt;HTTP status, when available.&lt;/li&gt;
&lt;li&gt;A server-issued request identifier, when available.&lt;/li&gt;
&lt;li&gt;Whether a network transition occurred near the failure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoid logging authorization headers, session cookies, full response bodies or URLs containing sensitive query parameters.&lt;/p&gt;

&lt;p&gt;Then compare client observations with the relevant server or gateway logs.&lt;/p&gt;

&lt;p&gt;If the application server received nothing, investigate earlier stages—but remember that incomplete logging can also hide a request. If a gateway returned an error, inspect that layer before changing the app’s connectivity handling.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do not fix a misleading message by weakening security
&lt;/h2&gt;

&lt;p&gt;A TLS error deserves investigation.&lt;/p&gt;

&lt;p&gt;Check the hostname, certificate chain, device time and relevant network configuration. Do not turn off certificate validation just to make the request succeed.&lt;/p&gt;

&lt;p&gt;Similarly, automatically asking every affected user to disconnect their VPN can hide the actual defect. A controlled comparison can help debugging; it should not substitute for understanding the failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make one failure easy to explain
&lt;/h2&gt;

&lt;p&gt;Start with the code path that currently turns every error into “No internet.”&lt;/p&gt;

&lt;p&gt;Preserve the underlying error, inspect HTTP status explicitly and keep decoding failures separate. Then test those paths deliberately.&lt;/p&gt;

&lt;p&gt;The goal is a message you can defend:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The connection was interrupted.&lt;/p&gt;

&lt;p&gt;The service rejected the request.&lt;/p&gt;

&lt;p&gt;The app could not read the response.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each tells the user something useful—and gives the developer a better place to start.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>debugging</category>
      <category>networking</category>
    </item>
    <item>
      <title>Your Android App Says “No Internet” With a VPN Connected: Is Your Connectivity Check Wrong?</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Fri, 13 Nov 2026 11:08:03 +0000</pubDate>
      <link>https://dev.to/klarvpn/your-android-app-says-no-internet-with-a-vpn-connected-is-your-connectivity-check-wrong-4a4i</link>
      <guid>https://dev.to/klarvpn/your-android-app-says-no-internet-with-a-vpn-connected-is-your-connectivity-check-wrong-4a4i</guid>
      <description>&lt;p&gt;Your Android app works over Wi-Fi. You connect a VPN, reopen the app and immediately see “No internet connection.”&lt;/p&gt;

&lt;p&gt;Meanwhile, another app loads new content without a problem.&lt;/p&gt;

&lt;p&gt;Before changing DNS settings or blaming the VPN server, check whether your app actually attempted a request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An offline message can come from a faulty connectivity check before any network operation starts.&lt;/strong&gt; If the app rejects a connection based on its transport type, the error may describe your code’s assumptions rather than the phone’s connectivity.&lt;/p&gt;

&lt;p&gt;Here is how to investigate.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Find the code that decides the app is offline
&lt;/h2&gt;

&lt;p&gt;Search for the condition that displays the message or prevents the request.&lt;/p&gt;

&lt;p&gt;A transport-based check might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;acceptedTransport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasTransport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;TRANSPORT_WIFI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
    &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasTransport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;TRANSPORT_CELLULAR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That tells you whether those transports are reported. It does not establish whether your API is reachable.&lt;/p&gt;

&lt;p&gt;Android networks can also report Ethernet or VPN transport. A network can have multiple transports at once, including a VPN and its underlying connection.&lt;/p&gt;

&lt;p&gt;That means a Wi-Fi-or-cellular check will not necessarily fail for every VPN. The broader problem is using a transport list as an internet-access test.&lt;/p&gt;

&lt;p&gt;Also look for an explicit VPN rejection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;consideredOnline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasCapability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NET_CAPABILITY_INTERNET&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasTransport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;TRANSPORT_VPN&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This labels a VPN connection offline regardless of whether requests would succeed.&lt;/p&gt;

&lt;p&gt;If your application intentionally restricts VPN use, that is a separate product policy. “No internet connection” is still an inaccurate explanation of that decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Separate transport, validation and service reachability
&lt;/h2&gt;

&lt;p&gt;These observations answer different questions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observation&lt;/th&gt;
&lt;th&gt;What it tells you&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Network transport&lt;/td&gt;
&lt;td&gt;How Android describes the connection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NET_CAPABILITY_INTERNET&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The network is configured for internet access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NET_CAPABILITY_VALIDATED&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Android’s probes have validated public internet access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Successful API request&lt;/td&gt;
&lt;td&gt;That particular operation reached a service and received a response&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;INTERNET&lt;/code&gt; is not proof of working connectivity. A network behind a captive portal can have that capability.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;VALIDATED&lt;/code&gt; provides stronger evidence, but it does not guarantee access to your backend. Your endpoint could still fail because of DNS, TLS, filtering or a server problem.&lt;/p&gt;

&lt;p&gt;The reverse deserves care too: an unvalidated network may still reach a particular private service.&lt;/p&gt;

&lt;p&gt;Use these signals to explain the network state. Keep the actual request result separate.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Trace changes to the app’s default network
&lt;/h2&gt;

&lt;p&gt;For an app using ordinary default routing, observe the default network rather than searching for any available Wi-Fi connection.&lt;/p&gt;

&lt;p&gt;The following diagnostic class logs network events and selected capabilities. It targets Android 7.0/API 24 or later.&lt;/p&gt;

&lt;p&gt;Add these permissions as children of the manifest element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.ACCESS_NETWORK_STATE"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.INTERNET"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add the diagnostic observer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;android&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Context&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;android&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ConnectivityManager&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;android&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Network&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;android&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;android&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Log&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DefaultNetworkTrace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;applicationContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getSystemService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;ConnectivityManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;started&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;callback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ConnectivityManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NetworkCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onAvailable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;network&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Network&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Default network available: $network"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

            &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onCapabilitiesChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;network&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Network&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;internet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasCapability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NET_CAPABILITY_INTERNET&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;validated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasCapability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NET_CAPABILITY_VALIDATED&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;vpn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;capabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasTransport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;TRANSPORT_VPN&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt;

                &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="s2"&gt;"network=$network "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                        &lt;span class="s2"&gt;"internet=$internet "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                        &lt;span class="s2"&gt;"validated=$validated vpn=$vpn"&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

            &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onLost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;network&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Network&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;d&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;TAG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Default network lost: $network"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Call start and stop from the same lifecycle thread.&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;started&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;registerDefaultNetworkCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;started&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;started&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unregisterNetworkCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;started&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;companion&lt;/span&gt; &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;TAG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"DefaultNetworkTrace"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep one observer instance for the lifecycle you are inspecting. Register it when observation starts and unregister it when it ends.&lt;/p&gt;

&lt;p&gt;This class records evidence; it does not implement a production connectivity state holder.&lt;/p&gt;

&lt;p&gt;Notice that &lt;code&gt;onAvailable()&lt;/code&gt; does not immediately fetch capabilities. Android’s guidance recommends using the information delivered to &lt;code&gt;onCapabilitiesChanged()&lt;/code&gt; rather than making synchronous queries inside the callback that can race with network updates.&lt;/p&gt;

&lt;p&gt;Callbacks also arrive asynchronously. No callback yet should not automatically become a permanent “offline” state.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Interpret network loss in context
&lt;/h2&gt;

&lt;p&gt;For a default-network callback, &lt;code&gt;onLost()&lt;/code&gt; means that network no longer satisfies the default-network tracking relationship. It does not mean every connection on the device has disappeared.&lt;/p&gt;

&lt;p&gt;This matters when a VPN connects, disconnects or changes its underlying network.&lt;/p&gt;

&lt;p&gt;Record the network identifier and event order. If your app maintains state, ensure an event associated with an older network cannot erase newer state.&lt;/p&gt;

&lt;p&gt;Avoid updating the UI directly from callback methods. Deliver state through your application’s chosen thread-safe mechanism and render it on the main thread.&lt;/p&gt;

&lt;p&gt;Also check how your HTTP client routes requests. Explicit process binding, network-bound sockets or a custom client configuration can make its route differ from the default network you are observing.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Inspect custom network filters
&lt;/h2&gt;

&lt;p&gt;If your app uses &lt;code&gt;registerNetworkCallback()&lt;/code&gt; with a custom &lt;code&gt;NetworkRequest&lt;/code&gt;, inspect the request itself.&lt;/p&gt;

&lt;p&gt;Android includes &lt;code&gt;NET_CAPABILITY_NOT_VPN&lt;/code&gt; among the default capabilities of a new network request. A filter that retains this capability excludes VPN networks from its matches.&lt;/p&gt;

&lt;p&gt;For a deliberate observer of internet-capable networks that should include VPNs, the request can remove that exclusion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NetworkRequest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addCapability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NET_CAPABILITY_INTERNET&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeCapability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;NetworkCapabilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;NET_CAPABILITY_NOT_VPN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This requires the &lt;code&gt;android.net.NetworkRequest&lt;/code&gt; import.&lt;/p&gt;

&lt;p&gt;Removing the exclusion allows VPN networks to match; it does not restrict the request to VPNs.&lt;/p&gt;

&lt;p&gt;A matching-network observer can report multiple networks. Finding one working network does not establish that your application’s requests use it. For default-routed requests, the default-network callback is usually the clearer diagnostic starting point.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Let the request produce evidence
&lt;/h2&gt;

&lt;p&gt;A connectivity precheck can become stale before the next line of code runs.&lt;/p&gt;

&lt;p&gt;For a user-triggered refresh, a useful design is to attempt the operation through the normal HTTP client, use an appropriate timeout and handle its outcome.&lt;/p&gt;

&lt;p&gt;Keep these results distinct:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The request was never attempted because a local guard rejected it.&lt;/li&gt;
&lt;li&gt;Hostname resolution failed.&lt;/li&gt;
&lt;li&gt;Connection establishment failed.&lt;/li&gt;
&lt;li&gt;TLS negotiation failed.&lt;/li&gt;
&lt;li&gt;The server returned an HTTP error.&lt;/li&gt;
&lt;li&gt;The response arrived but could not be processed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not collapse an HTTP &lt;code&gt;401&lt;/code&gt; or &lt;code&gt;403&lt;/code&gt; into “No internet.” An HTTP response means a server or intermediary responded; the next investigation concerns that response.&lt;/p&gt;

&lt;p&gt;Similarly, a generic public website loading does not prove that your application’s authenticated endpoint works.&lt;/p&gt;

&lt;p&gt;For diagnostic requests, use an endpoint you control and correlate client timestamps with server logs. Avoid recording tokens, private payloads or full URLs containing sensitive parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Reproduce the issue with controlled comparisons
&lt;/h2&gt;

&lt;p&gt;Keep the phone, app build, account and API operation unchanged.&lt;/p&gt;

&lt;p&gt;Test these four conditions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test&lt;/th&gt;
&lt;th&gt;Underlying network&lt;/th&gt;
&lt;th&gt;VPN&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;Wi-Fi&lt;/td&gt;
&lt;td&gt;Disconnected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;Same Wi-Fi&lt;/td&gt;
&lt;td&gt;Connected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;Cellular&lt;/td&gt;
&lt;td&gt;Disconnected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;D&lt;/td&gt;
&lt;td&gt;Same cellular connection&lt;/td&gt;
&lt;td&gt;Connected&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For the &lt;a href="https://www.klarvpn.com/download/vpn-for-android" rel="noopener noreferrer"&gt;&lt;strong&gt;VPN for Android&lt;/strong&gt;&lt;/a&gt; used in the comparison, record its version, selected location and any app exclusions.&lt;/p&gt;

&lt;p&gt;In each state, capture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default-network events.&lt;/li&gt;
&lt;li&gt;Reported capabilities.&lt;/li&gt;
&lt;li&gt;Whether the app attempted the request.&lt;/li&gt;
&lt;li&gt;Request duration.&lt;/li&gt;
&lt;li&gt;HTTP status or exception category.&lt;/li&gt;
&lt;li&gt;The message displayed to the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then test connecting the VPN while the app remains open. A bug that appears only during transitions may involve stale state or callback handling rather than the initial capability check.&lt;/p&gt;

&lt;p&gt;Use non-sensitive test traffic for disconnected baselines.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Match the fix to the finding
&lt;/h2&gt;

&lt;p&gt;If the app blocks requests because it rejects VPN transport, correct that guard.&lt;/p&gt;

&lt;p&gt;If requests succeed while the UI remains offline, inspect the state updates and rendering path.&lt;/p&gt;

&lt;p&gt;If Android reports validated connectivity but the request fails, investigate the endpoint, DNS, TLS and server response.&lt;/p&gt;

&lt;p&gt;If the issue appears only when switching networks, inspect event ordering and how the HTTP client recovers.&lt;/p&gt;

&lt;p&gt;Adding &lt;code&gt;TRANSPORT_VPN&lt;/code&gt; to a Wi-Fi-or-cellular condition may make one reproduction pass. It still leaves transport type standing in for service reachability.&lt;/p&gt;

&lt;p&gt;A stronger design uses network capabilities as context and treats request outcomes as evidence about the operation the user actually needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before closing the bug
&lt;/h2&gt;

&lt;p&gt;Verify two things independently:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The app attempts an appropriate request over the intended connection.&lt;/li&gt;
&lt;li&gt;The UI accurately describes the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;“Your session expired,” “The server could not be reached” and “Waiting for a connection” describe different situations.&lt;/p&gt;

&lt;p&gt;The goal is to remove the incorrect assumption that produced “No internet”—and preserve enough information to diagnose a real failure when one occurs.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>networking</category>
      <category>debugging</category>
    </item>
    <item>
      <title>Your iOS App Works on Wi-Fi but Fails on a VPN: How to Debug the Difference</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Tue, 10 Nov 2026 11:59:35 +0000</pubDate>
      <link>https://dev.to/klarvpn/your-ios-app-works-on-wi-fi-but-fails-on-a-vpn-how-to-debug-the-difference-2kgn</link>
      <guid>https://dev.to/klarvpn/your-ios-app-works-on-wi-fi-but-fails-on-a-vpn-how-to-debug-the-difference-2kgn</guid>
      <description>&lt;p&gt;Your iOS app loads its dashboard over Wi-Fi. Turn on a VPN, repeat the request, and the app displays “Something went wrong.”&lt;/p&gt;

&lt;p&gt;It is tempting to stop there and label the issue a VPN problem. But that message could hide a failed hostname lookup, a connection timeout, a TLS error or an HTTP response your app handles incorrectly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A failure that appears when a VPN is enabled is a useful reproduction condition. It is not yet a diagnosis.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next step is to identify where the request stops progressing.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Compare the same request on the same network
&lt;/h2&gt;

&lt;p&gt;Wi-Fi and a VPN are not competing connection types. Your phone can use Wi-Fi as the underlying network while the VPN carries selected traffic over it.&lt;/p&gt;

&lt;p&gt;Start with two conditions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The same Wi-Fi network with the VPN disconnected.&lt;/li&gt;
&lt;li&gt;The same Wi-Fi network with the VPN connected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep the app build, device, account, endpoint and request payload unchanged.&lt;/p&gt;

&lt;p&gt;For the &lt;a href="https://www.klarvpn.com/download/vpn-for-iphone" rel="noopener noreferrer"&gt;&lt;strong&gt;iPhone VPN&lt;/strong&gt;&lt;/a&gt; used in your test, record the app version, selected location and relevant connection settings. These details make the reproduction specific enough to investigate.&lt;/p&gt;

&lt;p&gt;Also record whether another proxy, iCloud Private Relay or a device-management profile is involved.&lt;/p&gt;

&lt;p&gt;Repeat the comparison. A single failure might coincide with an unrelated server error or an expired session.&lt;/p&gt;

&lt;p&gt;Once the initial result is repeatable, compare cellular with and without the VPN. This helps establish whether the behaviour depends on the underlying network.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Preserve the actual error
&lt;/h2&gt;

&lt;p&gt;A generic error banner is appropriate for some user-facing situations. It is inadequate as your only diagnostic information.&lt;/p&gt;

&lt;p&gt;For a failed &lt;code&gt;URLSession&lt;/code&gt; request, capture the error domain and code. In a development build, a small logging helper can preserve those details without printing credentials or response bodies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Foundation&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;logRequestFailure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;nsError&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;NSError&lt;/span&gt;

    &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Error domain:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nsError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Error code:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nsError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;urlError&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;URLError&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"URL error code:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;urlError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rawValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call this from the error path of your existing request.&lt;/p&gt;

&lt;p&gt;Avoid logging complete URLs when query parameters contain tokens or personal information. Use an internal request identifier to connect client and server observations.&lt;/p&gt;

&lt;p&gt;Different errors lead to different investigations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cannotFindHost&lt;/code&gt;: investigate hostname resolution and the hostname itself.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cannotConnectToHost&lt;/code&gt;: investigate reachability and connection establishment.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;secureConnectionFailed&lt;/code&gt;: investigate the secure connection and trust configuration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;timedOut&lt;/code&gt;: investigate which stage consumed the available time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are starting points. An error code does not identify the responsible component by itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Separate transport errors from HTTP responses
&lt;/h2&gt;

&lt;p&gt;A request can reach a server and still fail at the application level.&lt;/p&gt;

&lt;p&gt;For example, a VPN-on request might receive HTTP &lt;code&gt;403&lt;/code&gt;, &lt;code&gt;429&lt;/code&gt; or &lt;code&gt;503&lt;/code&gt;. That is different from receiving no HTTP response because connection establishment failed.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;URLSession&lt;/code&gt;, inspect the response status explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;httpResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;HTTPURLResponse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"HTTP status:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Place this in the response-handling path of your existing request.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;403&lt;/code&gt; does not automatically mean “VPN blocked.” It could reflect authentication, authorization, an edge-security rule or another policy.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;429&lt;/code&gt; suggests rate limiting, but the response alone does not establish which key triggered the limit. The system might use an account, token, address or a combination.&lt;/p&gt;

&lt;p&gt;Find the matching request in your edge and application logs before changing the client.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Investigate DNS without changing the test
&lt;/h2&gt;

&lt;p&gt;If the hostname cannot be resolved, establish whether it is intended to be publicly resolvable.&lt;/p&gt;

&lt;p&gt;An internal development hostname may work through a local or corporate resolver but fail through another DNS path. That result differs from a public API hostname failing unexpectedly.&lt;/p&gt;

&lt;p&gt;Check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The exact hostname configured in the app.&lt;/li&gt;
&lt;li&gt;Whether it requires a private network or corporate DNS.&lt;/li&gt;
&lt;li&gt;Whether the VPN configuration changes DNS handling.&lt;/li&gt;
&lt;li&gt;Whether the failure affects one hostname or several.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A lookup from your laptop is supporting evidence, not proof of the iPhone’s resolution path.&lt;/p&gt;

&lt;p&gt;Avoid replacing an HTTPS hostname with a raw IP address as a quick fix. Doing so can change certificate validation and virtual-host routing, creating a different failure from the one you started with.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Measure request stages
&lt;/h2&gt;

&lt;p&gt;An overall duration tells you how long the request took. It does not explain where the time went.&lt;/p&gt;

&lt;p&gt;Apple’s &lt;code&gt;URLSessionTaskMetrics&lt;/code&gt; provides transaction-level observations through the session delegate. Useful fields include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;domainLookupStartDate&lt;/code&gt; and &lt;code&gt;domainLookupEndDate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;connectStartDate&lt;/code&gt; and &lt;code&gt;connectEndDate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;secureConnectionStartDate&lt;/code&gt; and &lt;code&gt;secureConnectionEndDate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;requestStartDate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;responseStartDate&lt;/code&gt; and &lt;code&gt;responseEndDate&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isReusedConnection&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compare VPN-off and VPN-on runs using the same instrumentation.&lt;/p&gt;

&lt;p&gt;Look for the earliest meaningful difference. Does resolution fail to complete? Does connection establishment take longer? Does a response arrive promptly with an unexpected HTTP status?&lt;/p&gt;

&lt;p&gt;Treat missing timestamps carefully. Reused connections or locally retrieved resources can leave connection-related fields empty. A missing value is not automatically evidence that a stage failed.&lt;/p&gt;

&lt;p&gt;Redirects can also produce multiple transactions. Inspect the sequence instead of assuming one task represents one network exchange.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Review timeout and connectivity behaviour
&lt;/h2&gt;

&lt;p&gt;A timeout setting should express an application requirement. Increasing it indefinitely can hide a failure while leaving users waiting.&lt;/p&gt;

&lt;p&gt;Apple distinguishes two configuration properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;timeoutIntervalForRequest&lt;/code&gt; controls the interval spent waiting for additional data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;timeoutIntervalForResource&lt;/code&gt; limits the overall time allowed for the resource transfer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For an ordinary foreground session, &lt;code&gt;waitsForConnectivity&lt;/code&gt; determines whether the session waits for suitable connectivity rather than failing immediately when it is unavailable.&lt;/p&gt;

&lt;p&gt;A configuration experiment might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;URLSessionConfiguration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;

&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;waitsForConnectivity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeoutIntervalForRequest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeoutIntervalForResource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These values are illustrative. Choose values appropriate to the operation and create the session with that configuration.&lt;/p&gt;

&lt;p&gt;Waiting for connectivity does not repair a DNS configuration, a rejected certificate or an HTTP authorization failure. It also does not automatically replay an interrupted operation safely.&lt;/p&gt;

&lt;p&gt;If you add retries, distinguish reads from writes. Repeating an order-creation request after an ambiguous timeout can create duplicate work unless the server supports appropriate idempotency controls.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Correlate with server-side evidence
&lt;/h2&gt;

&lt;p&gt;Attach a request identifier to a diagnostic request where your API supports it.&lt;/p&gt;

&lt;p&gt;Then check the matching observation at each layer you control:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Did the edge receive the request?&lt;/li&gt;
&lt;li&gt;Did it forward the request to the application?&lt;/li&gt;
&lt;li&gt;Did an access rule or rate limit act on it?&lt;/li&gt;
&lt;li&gt;Did the application return a response?&lt;/li&gt;
&lt;li&gt;Did the client receive that response?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The absence of an application log entry does not prove the request never reached your infrastructure. A CDN, load balancer or gateway may have rejected it first.&lt;/p&gt;

&lt;p&gt;If client addresses matter, use the address recorded by your trusted ingress configuration. Do not accept arbitrary client-supplied forwarding headers as evidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Avoid fixes that remove the evidence
&lt;/h2&gt;

&lt;p&gt;Several changes can make a symptom disappear without explaining it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disabling certificate validation.&lt;/li&gt;
&lt;li&gt;Adding broad App Transport Security exceptions.&lt;/li&gt;
&lt;li&gt;Replacing every failure with an automatic retry.&lt;/li&gt;
&lt;li&gt;Switching networks, VPN locations and app settings simultaneously.&lt;/li&gt;
&lt;li&gt;Treating a successful Safari request as proof that the native app should behave identically.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Safari and your app can differ in authentication, cookies, caching, request headers and networking configuration.&lt;/p&gt;

&lt;p&gt;Keep the reproduction narrow until you can describe the failure precisely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finish with a finding you can act on
&lt;/h2&gt;

&lt;p&gt;“Works without a VPN” is the beginning of the investigation.&lt;/p&gt;

&lt;p&gt;A useful finding identifies the failing stage and the evidence:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The VPN-on request reaches our edge and receives HTTP 403 before reaching the application. The matching request identifier appears in an access-rule event.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The app uses an internal hostname that resolves on the office network but fails under the tested VPN DNS configuration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Those findings lead to specific changes. They also give you something concrete to retest.&lt;/p&gt;

&lt;p&gt;Start with one repeatable request, preserve its error and status information, and follow it from the client to the service. Change the configuration only after the evidence points to the layer that needs attention.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>networking</category>
      <category>debugging</category>
      <category>security</category>
    </item>
    <item>
      <title>Your Browser Works, but curl Fails: Check Proxy Settings Before Blaming the VPN</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Thu, 05 Nov 2026 11:40:50 +0000</pubDate>
      <link>https://dev.to/klarvpn/your-browser-works-but-curl-fails-check-proxy-settings-before-blaming-the-vpn-19lj</link>
      <guid>https://dev.to/klarvpn/your-browser-works-but-curl-fails-check-proxy-settings-before-blaming-the-vpn-19lj</guid>
      <description>&lt;p&gt;A website loads in your browser. The same address times out in curl.&lt;/p&gt;

&lt;p&gt;Your VPN is connected, so it becomes the obvious suspect. But the browser and curl may be using different proxy settings, different exclusions or different configuration files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A successful browser request does not establish that curl takes the same network path.&lt;/strong&gt; Before changing VPN settings, find out what curl is actually trying to connect to.&lt;/p&gt;

&lt;p&gt;This walkthrough uses POSIX-style shell examples for Linux and macOS. The diagnostic sequence is useful elsewhere, but shell syntax and platform behaviour can differ.&lt;/p&gt;

&lt;h2&gt;
  
  
  A proxy and a VPN can both affect one request
&lt;/h2&gt;

&lt;p&gt;An application-level proxy receives a request on behalf of a client. A VPN affects traffic according to its routing and filtering policies.&lt;/p&gt;

&lt;p&gt;The two can operate together.&lt;/p&gt;

&lt;p&gt;For example, curl might connect to a proxy through the VPN. Or a browser might use a configured proxy while curl attempts a connection without one.&lt;/p&gt;

&lt;p&gt;Neither arrangement can be inferred from “the VPN is connected.”&lt;/p&gt;

&lt;p&gt;Browser configuration can also include a proxy auto-configuration script, commonly called a PAC file. curl does not automatically evaluate a browser’s PAC script.&lt;/p&gt;

&lt;p&gt;Start by establishing the settings used by each application rather than assuming they match.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Record the failing request
&lt;/h2&gt;

&lt;p&gt;Choose a repeatable URL you are authorised to test. Prefer a simple endpoint without authentication, cookies or state-changing behaviour.&lt;/p&gt;

&lt;p&gt;Set it once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;debug_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'REPLACE_WITH_YOUR_TEST_URL'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the placeholder with the complete URL.&lt;/p&gt;

&lt;p&gt;Then record the curl executable and version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-V&lt;/span&gt; curl
curl &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;command -V&lt;/code&gt; can reveal an alias, function or wrapper that changes how the command runs.&lt;/p&gt;

&lt;p&gt;On Windows, use &lt;code&gt;curl.exe&lt;/code&gt; when you intend to invoke the curl executable rather than a shell command with the same name. The remaining examples use Unix shell syntax.&lt;/p&gt;

&lt;p&gt;Keep the VPN connection and network unchanged during the initial comparisons.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Check which proxy variables are present
&lt;/h2&gt;

&lt;p&gt;curl can obtain proxy settings from its environment.&lt;/p&gt;

&lt;p&gt;Check the relevant variable names without printing their values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;proxy_var &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  http_proxy https_proxy all_proxy no_proxy &lt;span class="se"&gt;\&lt;/span&gt;
  HTTP_PROXY HTTPS_PROXY ALL_PROXY NO_PROXY
&lt;span class="k"&gt;do
  if &lt;/span&gt;&lt;span class="nb"&gt;printenv&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$proxy_var&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s is set\n'&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$proxy_var&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi
done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reports presence, including variables with empty values. Inspect the actual values privately.&lt;/p&gt;

&lt;p&gt;A proxy address may contain credentials, so avoid pasting a full environment dump into a support ticket.&lt;/p&gt;

&lt;p&gt;For curl, the important relationships are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scheme-specific variables such as &lt;code&gt;https_proxy&lt;/code&gt; select a proxy for that URL scheme.&lt;/li&gt;
&lt;li&gt;A scheme-specific setting takes precedence over &lt;code&gt;ALL_PROXY&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NO_PROXY&lt;/code&gt; and &lt;code&gt;no_proxy&lt;/code&gt; define destinations that should bypass the selected proxy.&lt;/li&gt;
&lt;li&gt;curl deliberately treats lowercase &lt;code&gt;http_proxy&lt;/code&gt; differently from uppercase &lt;code&gt;HTTP_PROXY&lt;/code&gt;; on case-sensitive systems, the uppercase form is not its HTTP proxy setting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not assume another HTTP client implements identical rules.&lt;/p&gt;

&lt;p&gt;If conflicting uppercase and lowercase values exist, remove the ambiguity through your approved configuration rather than assuming the client chooses the value you intended.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Inspect one ordinary curl request
&lt;/h2&gt;

&lt;p&gt;Run a bounded request with verbose output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--verbose&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--connect-timeout&lt;/span&gt; 5 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--max-time&lt;/span&gt; 20 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; /dev/null &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$debug_url&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for the stage where it stops:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resolving a proxy hostname.&lt;/li&gt;
&lt;li&gt;Connecting to a proxy.&lt;/li&gt;
&lt;li&gt;Establishing an HTTP CONNECT tunnel.&lt;/li&gt;
&lt;li&gt;Resolving or connecting to the destination directly.&lt;/li&gt;
&lt;li&gt;Negotiating TLS.&lt;/li&gt;
&lt;li&gt;Receiving an HTTP response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Verbose output can expose headers, hostnames and other sensitive details. Review and redact it before sharing.&lt;/p&gt;

&lt;p&gt;Also distinguish an HTTP error from a connection failure. A &lt;code&gt;403&lt;/code&gt; response means an HTTP exchange occurred; it does not mean the response was useful or that the VPN caused the rejection.&lt;/p&gt;

&lt;p&gt;A timeout gives less information. You still need to identify which connection attempt timed out.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Repeat without curl’s default configuration file
&lt;/h2&gt;

&lt;p&gt;Environment variables are only part of curl’s configuration.&lt;/p&gt;

&lt;p&gt;A default curl configuration file can add options you did not type, including proxy settings. Its location depends on the platform and environment.&lt;/p&gt;

&lt;p&gt;Compare the previous request with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--verbose&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--connect-timeout&lt;/span&gt; 5 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--max-time&lt;/span&gt; 20 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; /dev/null &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$debug_url&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Put &lt;code&gt;-q&lt;/code&gt; first among curl’s arguments.&lt;/strong&gt; It prevents curl from loading its default configuration file.&lt;/p&gt;

&lt;p&gt;It does not remove proxy environment variables. It also does not neutralise options inserted by a wrapper or an explicitly supplied configuration file.&lt;/p&gt;

&lt;p&gt;If the ordinary request fails but this request works, investigate the default configuration file. Something loaded from it is affecting the result; that does not yet establish that a proxy option is responsible.&lt;/p&gt;

&lt;p&gt;Inspect the difference before deleting the file or changing unrelated settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Test without an explicit proxy, where permitted
&lt;/h2&gt;

&lt;p&gt;If your network permits direct access to the test destination, make one more comparison:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--noproxy&lt;/span&gt; &lt;span class="s1"&gt;'*'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--verbose&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--connect-timeout&lt;/span&gt; 5 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--max-time&lt;/span&gt; 20 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; /dev/null &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$debug_url&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quote the asterisk so the shell does not expand it into filenames.&lt;/p&gt;

&lt;p&gt;This tells curl not to use a selected application-level proxy for the request. It does not disconnect the VPN, bypass its routing policy or remove transparent network intermediaries.&lt;/p&gt;

&lt;p&gt;Do not run this comparison where direct access would violate a managed network policy.&lt;/p&gt;

&lt;p&gt;Keep the observations narrow:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;th&gt;What to investigate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Ordinary request fails; &lt;code&gt;-q&lt;/code&gt; works&lt;/td&gt;
&lt;td&gt;Options in curl’s default configuration file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;-q&lt;/code&gt; fails; &lt;code&gt;-q --noproxy '*'&lt;/code&gt; works&lt;/td&gt;
&lt;td&gt;Proxy selection, reachability, authentication or handling of the destination&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Proxy-enabled request works; no-proxy request fails&lt;/td&gt;
&lt;td&gt;Whether the destination requires the approved proxy or a different network path&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;All requests fail&lt;/td&gt;
&lt;td&gt;DNS, routing, TLS, destination access or another shared cause&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Requests return different HTTP statuses&lt;/td&gt;
&lt;td&gt;Different server/proxy responses, authentication or request handling&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These comparisons narrow the cause. They do not prove that a VPN is healthy or faulty.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Check whether NO_PROXY matches the intended destination
&lt;/h2&gt;

&lt;p&gt;An exclusion can explain why one hostname works while another fails.&lt;/p&gt;

&lt;p&gt;For example, a curl configuration might exclude:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;localhost,127.0.0.1,.corp.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That may be intentional for internal services.&lt;/p&gt;

&lt;p&gt;But a stale exclusion can also make curl attempt a direct connection to a destination that requires a proxy.&lt;/p&gt;

&lt;p&gt;The opposite problem is possible too: an internal hostname may be sent to a proxy that cannot reach it.&lt;/p&gt;

&lt;p&gt;Review the actual hostname in the request, the exclusion list and any redirects. Do not assume every HTTP library interprets domain patterns and exclusions the same way.&lt;/p&gt;

&lt;p&gt;Avoid globally setting &lt;code&gt;NO_PROXY=*&lt;/code&gt; as a repair. It changes proxy selection for every matching request made by clients that honour that setting.&lt;/p&gt;

&lt;p&gt;A one-command comparison is easier to reason about than a permanent environment change.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Compare with the approved proxy explicitly
&lt;/h2&gt;

&lt;p&gt;If you know which proxy the request should use, test that configuration directly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;debug_proxy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'REPLACE_WITH_YOUR_APPROVED_PROXY_ADDRESS'&lt;/span&gt;

curl &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--proxy&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$debug_proxy&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--noproxy&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--verbose&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--connect-timeout&lt;/span&gt; 5 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--max-time&lt;/span&gt; 20 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--output&lt;/span&gt; /dev/null &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$debug_url&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the approved proxy address, including the appropriate scheme and port.&lt;/p&gt;

&lt;p&gt;The empty no-proxy list prevents an environment exclusion from silently skipping this proxy during the comparison.&lt;/p&gt;

&lt;p&gt;This example does not configure proxy authentication. Follow your organisation’s supported authentication method rather than placing passwords in shell history.&lt;/p&gt;

&lt;p&gt;If this works while the environment-driven request fails, compare the effective proxy and exclusion settings.&lt;/p&gt;

&lt;p&gt;If it fails, identify the stage: proxy lookup, proxy connection, authentication, tunnel establishment or the destination request.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. If proxy selection is correct, investigate the next layer
&lt;/h2&gt;

&lt;p&gt;A browser and curl can still differ after you align their proxy paths.&lt;/p&gt;

&lt;p&gt;Possible differences include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Certificate trust stores or required enterprise certificates.&lt;/li&gt;
&lt;li&gt;Browser login sessions and cookies.&lt;/li&gt;
&lt;li&gt;Application-specific VPN exclusions.&lt;/li&gt;
&lt;li&gt;DNS configuration.&lt;/li&gt;
&lt;li&gt;IPv4 and IPv6 availability.&lt;/li&gt;
&lt;li&gt;Request headers or server-side access rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not make &lt;code&gt;--insecure&lt;/code&gt; the permanent answer to a certificate error. Investigate the certificate chain and the approved trust configuration.&lt;/p&gt;

&lt;p&gt;Similarly, copying every browser header into curl can obscure the issue. Establish which part of the request is required rather than changing many variables together.&lt;/p&gt;

&lt;p&gt;When &lt;a href="https://www.klarvpn.com/blog/how-to-check-if-vpn-is-working" rel="noopener noreferrer"&gt;&lt;strong&gt;checking whether a VPN is working&lt;/strong&gt;&lt;/a&gt;, remember that a browser-based observation describes that browser request. A terminal application needs its own investigation when its behaviour differs.&lt;/p&gt;

&lt;h2&gt;
  
  
  End with a finding that identifies the next step
&lt;/h2&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The browser works, so curl must be broken.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Write:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;curl attempts to reach an old proxy from its environment. The same request succeeds without that explicit proxy on a network where direct access is permitted.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The approved proxy is reachable, but curl receives a proxy authentication error. The next step is authentication configuration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Both applications use the intended proxy, but curl fails certificate validation. We need to investigate its trust configuration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each statement gives you a specific problem to solve.&lt;/p&gt;

&lt;p&gt;Check the executable, configuration file, proxy variables and exclusions before changing VPN settings. The useful result is an explanation of the request path—not simply a command that happens to succeed.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>debugging</category>
      <category>security</category>
      <category>linux</category>
    </item>
    <item>
      <title>Your VPN Works on the Host—Why Can’t Your Docker Container Resolve DNS?</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Tue, 03 Nov 2026 17:36:18 +0000</pubDate>
      <link>https://dev.to/klarvpn/your-vpn-works-on-the-host-why-cant-your-docker-container-resolve-dns-2gp6</link>
      <guid>https://dev.to/klarvpn/your-vpn-works-on-the-host-why-cant-your-docker-container-resolve-dns-2gp6</guid>
      <description>&lt;p&gt;Your VPN connects successfully. An internal hostname resolves on your laptop. The same hostname fails inside your application container.&lt;/p&gt;

&lt;p&gt;It is tempting to replace the container’s DNS server and move on. Sometimes that changes the result. Sometimes it breaks internal names or sends queries somewhere you did not intend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A working host connection does not establish that a container can reach the same DNS resolver or destination.&lt;/strong&gt; Start by separating three questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Which resolver is being used?&lt;/li&gt;
&lt;li&gt;Can the container reach that resolver?&lt;/li&gt;
&lt;li&gt;Can the container reach the application after resolution succeeds?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This walkthrough focuses on Linux containers. Native Linux Docker Engine and Docker Desktop have different networking paths, so we will distinguish them where it matters.&lt;/p&gt;

&lt;p&gt;The commands are diagnostic examples, not results from a tested VPN environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Confirm where Docker is actually running
&lt;/h2&gt;

&lt;p&gt;Before inspecting your laptop’s routes, check which Docker daemon your commands address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker context show
docker info &lt;span class="nt"&gt;--format&lt;/span&gt; &lt;span class="s1"&gt;'{{.OperatingSystem}}'&lt;/span&gt;
docker version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A remote Docker context changes the investigation completely. Your local VPN connection does not automatically provide connectivity to containers running on a remote server.&lt;/p&gt;

&lt;p&gt;Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Host operating system.&lt;/li&gt;
&lt;li&gt;Docker Engine or Docker Desktop.&lt;/li&gt;
&lt;li&gt;Docker and VPN versions.&lt;/li&gt;
&lt;li&gt;Local or remote Docker daemon.&lt;/li&gt;
&lt;li&gt;Affected container and Docker network.&lt;/li&gt;
&lt;li&gt;Whether the failure affects public names, internal names or both.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also distinguish a device-wide VPN from a browser proxy or extension. A browser connection is not a test of container connectivity.&lt;/p&gt;

&lt;p&gt;Browser-based &lt;a href="https://www.klarvpn.com/blog/vpn-leak-test" rel="noopener noreferrer"&gt;&lt;strong&gt;IP, DNS and WebRTC checks&lt;/strong&gt;&lt;/a&gt; examine another environment again. They cannot establish which resolver an application container uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Test the affected container first
&lt;/h2&gt;

&lt;p&gt;Replace &lt;code&gt;app&lt;/code&gt; with the actual container name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;app &lt;span class="nb"&gt;cat&lt;/span&gt; /etc/resolv.conf

docker inspect app &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--format&lt;/span&gt; &lt;span class="s1"&gt;'{{json .HostConfig.Dns}}'&lt;/span&gt;

docker inspect app &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--format&lt;/span&gt; &lt;span class="s1"&gt;'{{json .NetworkSettings.Networks}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command shows the resolver configuration visible inside the container. The others help identify explicit DNS overrides and network membership.&lt;/p&gt;

&lt;p&gt;For standard Docker Engine networking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Containers on the default bridge receive resolver configuration derived from the host.&lt;/li&gt;
&lt;li&gt;Containers on user-defined networks normally use Docker’s embedded resolver at &lt;code&gt;127.0.0.11&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;External lookups through the embedded resolver are forwarded upstream.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Seeing &lt;code&gt;127.0.0.11&lt;/code&gt; is therefore not, by itself, an error.&lt;/p&gt;

&lt;p&gt;Do not replace it with &lt;code&gt;127.0.0.1&lt;/code&gt; or the host’s &lt;code&gt;127.0.0.53&lt;/code&gt; stub address without understanding the network namespace. In a typical bridge-networked container, loopback refers to the container itself.&lt;/p&gt;

&lt;p&gt;A host-local DNS listener is not automatically reachable through the same address from a container.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Compare the same hostname on both sides
&lt;/h2&gt;

&lt;p&gt;Use the exact hostname that fails in the application.&lt;/p&gt;

&lt;p&gt;For a Linux host with &lt;code&gt;getent&lt;/code&gt; available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;getent hosts api.corp.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, if the container includes the same utility:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;app getent hosts api.corp.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;api.corp.example&lt;/code&gt; is a placeholder. Replace it with your internal fully qualified hostname.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;nslookup&lt;/code&gt; is available, compare direct DNS queries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nslookup api.corp.example

docker &lt;span class="nb"&gt;exec &lt;/span&gt;app nslookup api.corp.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These tools answer related but different questions. &lt;code&gt;getent&lt;/code&gt; uses the system’s configured name-service lookup mechanisms. &lt;code&gt;nslookup&lt;/code&gt; queries DNS. Application runtimes can also cache answers or implement their own resolution behaviour.&lt;/p&gt;

&lt;p&gt;Record the tool alongside the result.&lt;/p&gt;

&lt;p&gt;If the application image lacks diagnostic utilities, use an approved toolbox image on the same Docker network. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--network&lt;/span&gt; project_default &lt;span class="se"&gt;\&lt;/span&gt;
  busybox:1.37 &lt;span class="se"&gt;\&lt;/span&gt;
  nslookup api.corp.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;project_default&lt;/code&gt; with the actual network.&lt;/p&gt;

&lt;p&gt;This is a comparison, not an exact replica of the application container. It does not automatically inherit that container’s DNS overrides or application configuration. A failure to pull the toolbox image is also a separate problem from DNS inside an already-running container.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Separate DNS failure from connection failure
&lt;/h2&gt;

&lt;p&gt;A hostname lookup and a connection to the returned address are different operations.&lt;/p&gt;

&lt;p&gt;If resolution succeeds, test the actual application port using a known, current address supplied by your infrastructure team.&lt;/p&gt;

&lt;p&gt;For example, where &lt;code&gt;nc&lt;/code&gt; is available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;app nc &lt;span class="nt"&gt;-vz&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt; 5 10.20.30.40 443
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the address and port with your destination. Netcat options vary between implementations.&lt;/p&gt;

&lt;p&gt;Interpret the result narrowly:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observation&lt;/th&gt;
&lt;th&gt;Next area to investigate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lookup fails, but the known destination IP and port are reachable&lt;/td&gt;
&lt;td&gt;Resolver selection, DNS reachability or DNS response&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lookup succeeds, but the destination port is unreachable&lt;/td&gt;
&lt;td&gt;Routing, firewall, service availability or access policy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Both fail&lt;/td&gt;
&lt;td&gt;Investigate DNS and general connectivity separately&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lookup and TCP connection succeed, but the application fails&lt;/td&gt;
&lt;td&gt;TLS, proxy settings, authentication or application behaviour&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A successful TCP connection does not validate TLS or application health. A failed ping does not establish that the destination is unreachable; ICMP may be blocked.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Query the intended resolver directly
&lt;/h2&gt;

&lt;p&gt;If you know the approved DNS server for the internal domain, test it explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;app &lt;span class="se"&gt;\&lt;/span&gt;
  nslookup api.corp.example 10.20.0.53
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;10.20.0.53&lt;/code&gt; is an example address. Use the resolver assigned or approved for your network.&lt;/p&gt;

&lt;p&gt;This separates “which resolver was selected?” from “can this resolver answer from this environment?”&lt;/p&gt;

&lt;p&gt;Useful distinctions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Timeout:&lt;/strong&gt; no response arrived within the tool’s timeout. Routing, filtering or resolver availability may be involved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NXDOMAIN:&lt;/strong&gt; the responding DNS system says the name does not exist. Check the queried name, resolver and split-DNS configuration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SERVFAIL:&lt;/strong&gt; resolution failed at the responding DNS system. This is not the same as a network timeout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Address returned:&lt;/strong&gt; the lookup succeeded for that query; application connectivity still needs testing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the same resolver answers on the host but times out from the container, investigate the path between the container and that resolver.&lt;/p&gt;

&lt;p&gt;Do not treat switching to a public resolver as a universal fix. It may resolve public names while remaining unable to answer private ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. On native Linux Engine, inspect routes and subnet overlap
&lt;/h2&gt;

&lt;p&gt;The following host commands apply to native Linux networking. They are not equivalent checks for Docker Desktop’s internal VM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ip route get 10.20.0.53
ip route get 10.20.30.40

docker network inspect project_default &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--format&lt;/span&gt; &lt;span class="s1"&gt;'{{json .IPAM.Config}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the container includes the &lt;code&gt;ip&lt;/code&gt; utility, inspect its view too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;app ip route
docker &lt;span class="nb"&gt;exec &lt;/span&gt;app ip route get 10.20.0.53
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A container route pointing at its Docker gateway does not prove that the rest of the journey enters the VPN.&lt;/p&gt;

&lt;p&gt;Check whether a Docker subnet overlaps a network reached through the VPN. For example, a container network and a corporate network might both use the same private address range. That creates ambiguity about where traffic should go.&lt;/p&gt;

&lt;p&gt;Choose replacement subnets against the actual routes in your environment. There is no private range that is guaranteed to be conflict-free everywhere.&lt;/p&gt;

&lt;p&gt;Also inspect VPN and host firewall policies affecting forwarded container traffic. A rule that permits a connection originating on the host may not permit the forwarded path.&lt;/p&gt;

&lt;p&gt;Avoid flushing firewall rules or disabling the VPN kill switch as a general troubleshooting step. Those changes alter the conditions you are trying to understand.&lt;/p&gt;

&lt;p&gt;Rootless Docker introduces another networking layer; do not assume a rootful bridge-network diagnosis applies unchanged.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. On Docker Desktop, account for the VM and backend
&lt;/h2&gt;

&lt;p&gt;Docker Desktop runs Linux containers inside a VM. Network traffic reaches the host through Desktop’s networking components.&lt;/p&gt;

&lt;p&gt;That means a successful host lookup does not test the whole container-to-resolver path.&lt;/p&gt;

&lt;p&gt;Check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether the VPN or endpoint policy permits Docker Desktop’s networking backend.&lt;/li&gt;
&lt;li&gt;Whether the failure occurs only after connecting or reconnecting the VPN.&lt;/li&gt;
&lt;li&gt;Whether it affects internal domains, public domains or both.&lt;/li&gt;
&lt;li&gt;Whether the configuration depends on IPv4, IPv6 or an HTTP proxy.&lt;/li&gt;
&lt;li&gt;Whether the affected container predates the network change.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On macOS and Windows, do not expect a host-side &lt;code&gt;docker0&lt;/code&gt; interface to behave like native Linux Engine networking.&lt;/p&gt;

&lt;p&gt;If restarting Desktop changes the result, record that observation. It suggests a state-dependent interaction worth investigating; it does not establish a permanent fix or identify the responsible component.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Check short names and Compose service names separately
&lt;/h2&gt;

&lt;p&gt;Suppose &lt;code&gt;api.corp.example&lt;/code&gt; resolves but &lt;code&gt;api&lt;/code&gt; does not.&lt;/p&gt;

&lt;p&gt;That points toward search-domain behaviour rather than a complete DNS outage.&lt;/p&gt;

&lt;p&gt;An explicit Compose configuration can look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;your-app:your-tag&lt;/span&gt;
    &lt;span class="na"&gt;dns&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;${CORP_DNS_IP}"&lt;/span&gt;
    &lt;span class="na"&gt;dns_search&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;corp.example&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set &lt;code&gt;CORP_DNS_IP&lt;/code&gt; to an approved resolver reachable from the container environment. This is a configuration example, not a recommendation to override DNS before diagnosis.&lt;/p&gt;

&lt;p&gt;A static resolver list may also be insufficient for domain-specific split-DNS requirements.&lt;/p&gt;

&lt;p&gt;Compose service discovery is another case. A service named &lt;code&gt;db&lt;/code&gt; normally needs shared network membership with the service querying it. A corporate DNS server should not be expected to resolve Docker-only service names.&lt;/p&gt;

&lt;p&gt;Check whether you are debugging:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An external public hostname.&lt;/li&gt;
&lt;li&gt;An internal corporate hostname.&lt;/li&gt;
&lt;li&gt;A short name requiring a search suffix.&lt;/li&gt;
&lt;li&gt;A Compose service name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not apply the same fix to all four.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Retest the application after a controlled change
&lt;/h2&gt;

&lt;p&gt;Once the evidence supports a change, apply it to the affected service and retest.&lt;/p&gt;

&lt;p&gt;For Compose configuration changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose up &lt;span class="nt"&gt;-d&lt;/span&gt; app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can recreate the service when necessary and may interrupt it. A plain &lt;code&gt;docker compose restart&lt;/code&gt; does not apply changes made to the Compose configuration.&lt;/p&gt;

&lt;p&gt;Then repeat:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The hostname lookup.&lt;/li&gt;
&lt;li&gt;The destination-port check.&lt;/li&gt;
&lt;li&gt;The actual application request.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Where permitted, repeat after a VPN reconnect or network change. Record what changed and what remained stable.&lt;/p&gt;

&lt;p&gt;Avoid describing a one-time successful lookup as proof that the configuration works across every connection state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finish with a finding you can explain
&lt;/h2&gt;

&lt;p&gt;“Docker DNS is broken” is a symptom.&lt;/p&gt;

&lt;p&gt;A more useful finding is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The host resolves the internal hostname through the corporate resolver. The application container times out when querying that same resolver directly. We need to investigate resolver reachability from the container network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The fully qualified name resolves inside the container, but the short name fails. We need to check the search-domain configuration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;DNS resolution succeeds, but the application port is unreachable. The remaining failure is beyond name resolution.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each statement narrows the next step.&lt;/p&gt;

&lt;p&gt;Start with the affected container, separate resolution from connectivity, and change one setting at a time. A successful host connection is valuable evidence—but it is only one part of the path.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>networking</category>
      <category>security</category>
      <category>vpn</category>
    </item>
    <item>
      <title>A Developer Roadmap for Building Production-Ready AI Agents</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Tue, 23 Jun 2026 17:10:00 +0000</pubDate>
      <link>https://dev.to/klarvpn/a-developer-roadmap-for-building-production-ready-ai-agents-4250</link>
      <guid>https://dev.to/klarvpn/a-developer-roadmap-for-building-production-ready-ai-agents-4250</guid>
      <description>&lt;p&gt;Most AI agent projects start with a simple idea:&lt;/p&gt;

&lt;p&gt;Connect an LLM to a few tools and let it complete tasks.&lt;/p&gt;

&lt;p&gt;That works well for demos.&lt;/p&gt;

&lt;p&gt;It does not always work well in production.&lt;/p&gt;

&lt;p&gt;A real AI agent needs more than a model and a prompt. It needs a defined job, a controlled environment, reliable tool access, memory boundaries, retrieval, guardrails, observability, deployment infrastructure, and a clear strategy for how much autonomy it should have.&lt;/p&gt;

&lt;p&gt;The difference between a demo agent and a useful agent is not only intelligence.&lt;/p&gt;

&lt;p&gt;It is system design.&lt;/p&gt;

&lt;p&gt;This post breaks down a practical roadmap for developers who want to build AI agents that can move beyond prototypes and become part of real workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with a narrow job
&lt;/h2&gt;

&lt;p&gt;Before choosing a model, framework, vector database, or agent library, define the job.&lt;/p&gt;

&lt;p&gt;An AI agent should not begin as a vague assistant that can “do anything.”&lt;/p&gt;

&lt;p&gt;That usually leads to unpredictable behavior.&lt;/p&gt;

&lt;p&gt;Start with a specific workflow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Qualify inbound leads&lt;/li&gt;
&lt;li&gt;Summarize support tickets&lt;/li&gt;
&lt;li&gt;Research companies before sales calls&lt;/li&gt;
&lt;li&gt;Extract structured data from documents&lt;/li&gt;
&lt;li&gt;Monitor system alerts&lt;/li&gt;
&lt;li&gt;Prepare CRM updates&lt;/li&gt;
&lt;li&gt;Route customer requests&lt;/li&gt;
&lt;li&gt;Generate internal reports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The more specific the job, the easier it becomes to design the system around it.&lt;/p&gt;

&lt;p&gt;A good agent has clear inputs, expected outputs, success criteria, and failure conditions.&lt;/p&gt;

&lt;p&gt;For example, “help with sales” is too broad.&lt;/p&gt;

&lt;p&gt;“Research a new inbound lead, compare it against our ICP, generate a lead score, and draft a short sales note” is much better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Think in systems, not prompts
&lt;/h2&gt;

&lt;p&gt;A prompt is only one part of an AI agent.&lt;/p&gt;

&lt;p&gt;A production-ready agent usually looks more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User / Trigger
      ↓
Task Definition
      ↓
Model Reasoning
      ↓
Tools + APIs
      ↓
Memory / Retrieval
      ↓
Guardrails
      ↓
Workflow Execution
      ↓
Logs + Monitoring
      ↓
Human Approval or Final Action
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model is important, but it is not the whole system.&lt;/p&gt;

&lt;p&gt;The real value comes from connecting reasoning to action safely.&lt;/p&gt;

&lt;p&gt;That means your architecture matters as much as your prompt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define the agent environment
&lt;/h2&gt;

&lt;p&gt;An AI agent needs an environment where it can do work.&lt;/p&gt;

&lt;p&gt;That environment may include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;Databases&lt;/li&gt;
&lt;li&gt;CRMs&lt;/li&gt;
&lt;li&gt;Internal tools&lt;/li&gt;
&lt;li&gt;Messaging platforms&lt;/li&gt;
&lt;li&gt;Documentation&lt;/li&gt;
&lt;li&gt;Workflow automation tools&lt;/li&gt;
&lt;li&gt;File storage&lt;/li&gt;
&lt;li&gt;Calendars&lt;/li&gt;
&lt;li&gt;Email systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A chatbot can sit outside the business process.&lt;/p&gt;

&lt;p&gt;An agent needs to operate inside it.&lt;/p&gt;

&lt;p&gt;For example, a support agent may need access to product documentation, past tickets, customer account data, subscription status, and escalation rules.&lt;/p&gt;

&lt;p&gt;A lead research agent may need access to company data, CRM records, qualification rules, website content, and email templates.&lt;/p&gt;

&lt;p&gt;A workflow automation agent may need access to tools like n8n, webhooks, databases, and third-party APIs.&lt;/p&gt;

&lt;p&gt;This is where agents become useful.&lt;/p&gt;

&lt;p&gt;They stop being text generators and start becoming workflow participants.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the agent tools carefully
&lt;/h2&gt;

&lt;p&gt;Tools are what allow an agent to act.&lt;/p&gt;

&lt;p&gt;Without tools, the agent can only respond.&lt;/p&gt;

&lt;p&gt;With tools, it can search, fetch, update, create, trigger, summarize, classify, route, and execute.&lt;/p&gt;

&lt;p&gt;But tool access should be designed carefully.&lt;/p&gt;

&lt;p&gt;A tool should have a clear purpose.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get_customer_profile(customer_id)
create_support_ticket(summary, priority)
search_docs(query)
draft_email(recipient, context)
update_crm_field(record_id, field, value)
trigger_n8n_workflow(workflow_id, payload)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These tools are specific.&lt;/p&gt;

&lt;p&gt;That is good.&lt;/p&gt;

&lt;p&gt;Avoid giving agents vague or overly powerful tools too early. A generic “run anything” tool may be flexible, but it is also risky.&lt;/p&gt;

&lt;p&gt;Good agent design usually means giving the model narrow tools with predictable inputs and outputs.&lt;/p&gt;

&lt;p&gt;The more structured the tools are, the more reliable the agent becomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use retrieval before fine-tuning
&lt;/h2&gt;

&lt;p&gt;Many teams think they need fine-tuning as soon as an agent gives weak answers.&lt;/p&gt;

&lt;p&gt;Often, they do not.&lt;/p&gt;

&lt;p&gt;If the agent lacks knowledge, retrieval is usually the better first step.&lt;/p&gt;

&lt;p&gt;Retrieval lets the agent access relevant documents, policies, product information, customer data, or internal knowledge at runtime.&lt;/p&gt;

&lt;p&gt;That is useful because most business knowledge changes over time.&lt;/p&gt;

&lt;p&gt;You do not want to retrain a model every time a pricing page, product doc, onboarding process, or internal rule changes.&lt;/p&gt;

&lt;p&gt;A simple retrieval layer can often solve the first version of the problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User question or task
      ↓
Search relevant knowledge
      ↓
Add context to model
      ↓
Generate answer or action
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fine-tuning can be useful later for repeated formatting, tone, classification, or domain-specific behavior.&lt;/p&gt;

&lt;p&gt;But for most early agent systems, retrieval should come first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add memory only where it helps
&lt;/h2&gt;

&lt;p&gt;Memory sounds exciting, but it can make agents messy if added too early.&lt;/p&gt;

&lt;p&gt;Not every agent needs long-term memory.&lt;/p&gt;

&lt;p&gt;Some agents only need temporary task context.&lt;/p&gt;

&lt;p&gt;Some need access to execution history.&lt;/p&gt;

&lt;p&gt;Some need user preferences.&lt;/p&gt;

&lt;p&gt;Some need structured memory about projects, accounts, or recurring decisions.&lt;/p&gt;

&lt;p&gt;The important question is:&lt;/p&gt;

&lt;p&gt;What does this agent actually need to remember to do its job better?&lt;/p&gt;

&lt;p&gt;For example, a personal assistant may need preferences, recurring tasks, writing style, and calendar habits.&lt;/p&gt;

&lt;p&gt;A support agent may need recent customer issues and previous conversations.&lt;/p&gt;

&lt;p&gt;A document extraction agent may not need memory at all.&lt;/p&gt;

&lt;p&gt;Memory should make the agent more useful, not more unpredictable.&lt;/p&gt;

&lt;p&gt;In many cases, structured data is better than vague memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build guardrails early
&lt;/h2&gt;

&lt;p&gt;Guardrails should not be added after the agent is already deployed.&lt;/p&gt;

&lt;p&gt;They should be part of the first version.&lt;/p&gt;

&lt;p&gt;A guardrail defines what the agent can do, what it cannot do, when it should stop, and when it should ask for approval.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The agent can draft an email but cannot send it without approval.&lt;/li&gt;
&lt;li&gt;The agent can summarize a customer issue but cannot refund an order.&lt;/li&gt;
&lt;li&gt;The agent can update lead status but cannot delete CRM records.&lt;/li&gt;
&lt;li&gt;The agent can suggest a workflow but cannot deploy it automatically.&lt;/li&gt;
&lt;li&gt;The agent must say when it does not have enough information.&lt;/li&gt;
&lt;li&gt;The agent must escalate high-risk actions to a human.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not about making the agent less powerful.&lt;/p&gt;

&lt;p&gt;It is about making it safer to use.&lt;/p&gt;

&lt;p&gt;A useful production agent is not one that can do everything.&lt;/p&gt;

&lt;p&gt;It is one that does the right things reliably.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide the autonomy level
&lt;/h2&gt;

&lt;p&gt;Autonomy should be gradual.&lt;/p&gt;

&lt;p&gt;Do not start by giving the agent full control.&lt;/p&gt;

&lt;p&gt;A practical rollout looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Level 1: Suggest
Level 2: Draft
Level 3: Execute low-risk actions
Level 4: Execute multi-step workflows with limits
Level 5: Operate with broad autonomy and monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most teams should start at Level 1 or Level 2.&lt;/p&gt;

&lt;p&gt;Let the agent recommend actions.&lt;/p&gt;

&lt;p&gt;Then let it prepare work.&lt;/p&gt;

&lt;p&gt;Then let it execute low-risk tasks.&lt;/p&gt;

&lt;p&gt;Only expand autonomy once the system proves itself through real usage.&lt;/p&gt;

&lt;p&gt;This is how trust is built.&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat workflows as the product
&lt;/h2&gt;

&lt;p&gt;Many valuable agents are really agentic workflows.&lt;/p&gt;

&lt;p&gt;The agent is not always the entire product. Sometimes it is the reasoning layer inside a larger automation system.&lt;/p&gt;

&lt;p&gt;Example lead qualification workflow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;New lead submitted
      ↓
Fetch company information
      ↓
Compare against ICP
      ↓
Score lead
      ↓
Draft outreach message
      ↓
Update CRM
      ↓
Notify sales team
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AI is useful because it handles judgment, summarization, classification, and personalization between structured steps.&lt;/p&gt;

&lt;p&gt;This is why workflow automation matters so much for AI agents.&lt;/p&gt;

&lt;p&gt;At some point, your agent will need to connect with external systems, APIs, databases, and triggers. That is where platforms like n8n, Langflow, Dify, OpenWebUI, and similar open-source tools become part of the agent stack.&lt;/p&gt;

&lt;p&gt;Platforms like &lt;a href="https://www.agntable.com/" rel="noopener noreferrer"&gt;Agntable&lt;/a&gt; are built around this shift: helping teams run open-source AI tools and workflow automation infrastructure without getting stuck maintaining servers, deployments, monitoring, backups, and updates.&lt;/p&gt;

&lt;p&gt;Because once an agent becomes part of real work, infrastructure becomes part of the product.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add observability
&lt;/h2&gt;

&lt;p&gt;You cannot improve an agent you cannot inspect.&lt;/p&gt;

&lt;p&gt;A production agent should log:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inputs&lt;/li&gt;
&lt;li&gt;Outputs&lt;/li&gt;
&lt;li&gt;Tool calls&lt;/li&gt;
&lt;li&gt;Retrieved context&lt;/li&gt;
&lt;li&gt;Errors&lt;/li&gt;
&lt;li&gt;Approval decisions&lt;/li&gt;
&lt;li&gt;Execution results&lt;/li&gt;
&lt;li&gt;Latency&lt;/li&gt;
&lt;li&gt;Failed steps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is useful for debugging and evaluation.&lt;/p&gt;

&lt;p&gt;When something goes wrong, you need to know where it failed.&lt;/p&gt;

&lt;p&gt;Did the model misunderstand the instruction?&lt;/p&gt;

&lt;p&gt;Did retrieval return the wrong context?&lt;/p&gt;

&lt;p&gt;Did a tool fail?&lt;/p&gt;

&lt;p&gt;Was the input incomplete?&lt;/p&gt;

&lt;p&gt;Did the guardrail block the right action?&lt;/p&gt;

&lt;p&gt;Did the workflow fail after the agent made the right decision?&lt;/p&gt;

&lt;p&gt;Without logs, you are guessing.&lt;/p&gt;

&lt;p&gt;With observability, you can improve the system over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluate like software
&lt;/h2&gt;

&lt;p&gt;Do not judge an AI agent only by a few impressive examples.&lt;/p&gt;

&lt;p&gt;Create test cases.&lt;/p&gt;

&lt;p&gt;Use realistic inputs.&lt;/p&gt;

&lt;p&gt;Include edge cases.&lt;/p&gt;

&lt;p&gt;Check failure modes.&lt;/p&gt;

&lt;p&gt;Track whether the agent calls the right tools, follows rules, gives consistent outputs, and asks for help when uncertain.&lt;/p&gt;

&lt;p&gt;For example, if you are building a support agent, test it against:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple questions&lt;/li&gt;
&lt;li&gt;Ambiguous questions&lt;/li&gt;
&lt;li&gt;Angry customers&lt;/li&gt;
&lt;li&gt;Missing account data&lt;/li&gt;
&lt;li&gt;Outdated documentation&lt;/li&gt;
&lt;li&gt;Refund requests&lt;/li&gt;
&lt;li&gt;Escalation scenarios&lt;/li&gt;
&lt;li&gt;Unsupported product questions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A production agent should be evaluated like any other software system.&lt;/p&gt;

&lt;p&gt;It needs testing, monitoring, iteration, and rollback plans.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plan deployment early
&lt;/h2&gt;

&lt;p&gt;A local demo is not a production deployment.&lt;/p&gt;

&lt;p&gt;If an agent is useful, it will eventually need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A stable runtime&lt;/li&gt;
&lt;li&gt;Environment variables&lt;/li&gt;
&lt;li&gt;Secret management&lt;/li&gt;
&lt;li&gt;Persistent storage&lt;/li&gt;
&lt;li&gt;Queueing&lt;/li&gt;
&lt;li&gt;Database access&lt;/li&gt;
&lt;li&gt;Background workers&lt;/li&gt;
&lt;li&gt;Webhooks&lt;/li&gt;
&lt;li&gt;Monitoring&lt;/li&gt;
&lt;li&gt;Backups&lt;/li&gt;
&lt;li&gt;Update strategy&lt;/li&gt;
&lt;li&gt;Access controls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This part is easy to ignore during prototyping.&lt;/p&gt;

&lt;p&gt;But it becomes critical when the agent starts handling real workflows.&lt;/p&gt;

&lt;p&gt;If the agent only works while your laptop is open, it is not production-ready.&lt;/p&gt;

&lt;p&gt;If nobody knows when it fails, it is not production-ready.&lt;/p&gt;

&lt;p&gt;If there are no backups, it is not production-ready.&lt;/p&gt;

&lt;p&gt;If it has access to tools but no permission boundaries, it is not production-ready.&lt;/p&gt;

&lt;p&gt;The deployment layer matters because reliability creates trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical roadmap
&lt;/h2&gt;

&lt;p&gt;A developer-friendly roadmap for building AI agents looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define a narrow job.&lt;/li&gt;
&lt;li&gt;Map the workflow.&lt;/li&gt;
&lt;li&gt;Identify tools and data sources.&lt;/li&gt;
&lt;li&gt;Choose the model.&lt;/li&gt;
&lt;li&gt;Add retrieval if the agent needs knowledge.&lt;/li&gt;
&lt;li&gt;Add memory only where useful.&lt;/li&gt;
&lt;li&gt;Define guardrails and approval rules.&lt;/li&gt;
&lt;li&gt;Build the first version with limited autonomy.&lt;/li&gt;
&lt;li&gt;Test against real examples.&lt;/li&gt;
&lt;li&gt;Add logging and monitoring.&lt;/li&gt;
&lt;li&gt;Deploy in a reliable environment.&lt;/li&gt;
&lt;li&gt;Expand autonomy gradually.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This roadmap is slower than “just connect tools to an LLM.”&lt;/p&gt;

&lt;p&gt;But it is much closer to how useful agents actually get built.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;AI agents are not just prompts.&lt;/p&gt;

&lt;p&gt;They are systems that combine models, tools, memory, retrieval, workflows, permissions, testing, and infrastructure.&lt;/p&gt;

&lt;p&gt;The model matters, but the surrounding architecture matters just as much.&lt;/p&gt;

&lt;p&gt;A good agent does not need to be fully autonomous on day one.&lt;/p&gt;

&lt;p&gt;It needs to be useful, safe, observable, and reliable.&lt;/p&gt;

&lt;p&gt;That is what separates a demo from a production system.&lt;/p&gt;

&lt;p&gt;The future of AI agents will not only belong to teams with the best prompts.&lt;/p&gt;

&lt;p&gt;It will belong to teams that build the best systems around them.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>devops</category>
      <category>docker</category>
    </item>
    <item>
      <title>The Real Cost of Hosting n8n: Choosing the Right Infrastructure in 2026</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Tue, 16 Jun 2026 14:21:04 +0000</pubDate>
      <link>https://dev.to/klarvpn/the-real-cost-of-hosting-n8n-choosing-the-right-infrastructure-in-2026-2n1i</link>
      <guid>https://dev.to/klarvpn/the-real-cost-of-hosting-n8n-choosing-the-right-infrastructure-in-2026-2n1i</guid>
      <description>&lt;p&gt;When people start using n8n, they usually focus on workflows.&lt;/p&gt;

&lt;p&gt;That makes sense.&lt;/p&gt;

&lt;p&gt;The visual editor, API integrations, webhooks, databases, AI models, and automation possibilities are what make n8n attractive in the first place.&lt;/p&gt;

&lt;p&gt;But after the first few workflows are running, a different question starts to matter:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where should this thing live?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first glance, hosting seems simple. Spin up a VPS, install Docker, deploy n8n, and move on.&lt;/p&gt;

&lt;p&gt;In reality, hosting often becomes the biggest operational decision a team makes around n8n.&lt;/p&gt;

&lt;p&gt;The choice affects reliability, maintenance, scaling, security, backups, monitoring, workflow uptime, and ultimately how much time your team spends managing infrastructure instead of building automation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hosting is easy until workflows become important
&lt;/h2&gt;

&lt;p&gt;Most teams start small.&lt;/p&gt;

&lt;p&gt;Maybe it is a lead routing workflow.&lt;/p&gt;

&lt;p&gt;Maybe it is a Slack notification.&lt;/p&gt;

&lt;p&gt;Maybe it is a content automation process.&lt;/p&gt;

&lt;p&gt;Maybe it is an AI workflow connecting OpenAI, Airtable, and Notion.&lt;/p&gt;

&lt;p&gt;At this stage, a simple VPS is usually enough.&lt;/p&gt;

&lt;p&gt;The problem appears when workflows become business-critical.&lt;/p&gt;

&lt;p&gt;Now n8n is no longer a side project.&lt;/p&gt;

&lt;p&gt;It is handling customer onboarding, support operations, CRM synchronization, payment notifications, reporting pipelines, or AI-powered business processes.&lt;/p&gt;

&lt;p&gt;When that happens, downtime becomes expensive.&lt;/p&gt;

&lt;p&gt;A failed workflow is no longer just a technical issue. It becomes a business issue.&lt;/p&gt;

&lt;p&gt;This is why hosting deserves more attention than many teams initially give it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hidden responsibilities of self-hosting
&lt;/h2&gt;

&lt;p&gt;Developers often like the idea of self-hosting.&lt;/p&gt;

&lt;p&gt;You get complete control over the environment.&lt;/p&gt;

&lt;p&gt;You choose the server.&lt;/p&gt;

&lt;p&gt;You choose the database.&lt;/p&gt;

&lt;p&gt;You choose the region.&lt;/p&gt;

&lt;p&gt;You control the backups.&lt;/p&gt;

&lt;p&gt;You control security policies.&lt;/p&gt;

&lt;p&gt;You control updates.&lt;/p&gt;

&lt;p&gt;That flexibility is valuable.&lt;/p&gt;

&lt;p&gt;But every piece of control comes with ownership.&lt;/p&gt;

&lt;p&gt;If the server crashes, you fix it.&lt;/p&gt;

&lt;p&gt;If SSL expires, you fix it.&lt;/p&gt;

&lt;p&gt;If backups fail, you fix it.&lt;/p&gt;

&lt;p&gt;If PostgreSQL fills the disk, you fix it.&lt;/p&gt;

&lt;p&gt;If Docker breaks after an update, you fix it.&lt;/p&gt;

&lt;p&gt;If webhooks stop responding, you investigate it.&lt;/p&gt;

&lt;p&gt;None of these tasks are especially difficult on their own.&lt;/p&gt;

&lt;p&gt;The challenge is that they add up.&lt;/p&gt;

&lt;p&gt;Over time, infrastructure maintenance starts competing with workflow development for attention.&lt;/p&gt;

&lt;h2&gt;
  
  
  VPS hosting works well for technical teams
&lt;/h2&gt;

&lt;p&gt;For developers who are comfortable with Linux, Docker, networking, and databases, VPS hosting remains one of the most flexible ways to run n8n.&lt;/p&gt;

&lt;p&gt;Providers such as DigitalOcean, Hetzner, Hostinger, Kamatera, and ScalaHosting can all provide more than enough resources for many n8n workloads.&lt;/p&gt;

&lt;p&gt;The advantages are clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full control&lt;/li&gt;
&lt;li&gt;Lower infrastructure costs&lt;/li&gt;
&lt;li&gt;Flexible deployment options&lt;/li&gt;
&lt;li&gt;Complete ownership of data&lt;/li&gt;
&lt;li&gt;Freedom to customize&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The downside is operational responsibility.&lt;/p&gt;

&lt;p&gt;A VPS provider hosts your server.&lt;/p&gt;

&lt;p&gt;It does not host your n8n operations.&lt;/p&gt;

&lt;p&gt;There is a big difference between those two things.&lt;/p&gt;

&lt;h2&gt;
  
  
  The official n8n Cloud route
&lt;/h2&gt;

&lt;p&gt;The simplest path is usually n8n Cloud.&lt;/p&gt;

&lt;p&gt;It removes much of the infrastructure work and gives teams a hosted experience directly from the company behind the product.&lt;/p&gt;

&lt;p&gt;For many businesses, that simplicity is attractive.&lt;/p&gt;

&lt;p&gt;You can focus on workflows rather than deployment.&lt;/p&gt;

&lt;p&gt;You avoid most infrastructure decisions.&lt;/p&gt;

&lt;p&gt;You do not need to worry about Docker configuration, reverse proxies, SSL certificates, or server management.&lt;/p&gt;

&lt;p&gt;The tradeoff is that you are working within the platform's pricing model and environment rather than owning the entire stack.&lt;/p&gt;

&lt;p&gt;For many teams, that is a perfectly reasonable tradeoff.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why managed n8n hosting is growing
&lt;/h2&gt;

&lt;p&gt;There is a growing category between self-hosting and official cloud hosting.&lt;/p&gt;

&lt;p&gt;Managed n8n providers exist because many teams want the flexibility of n8n without the operational burden of maintaining servers.&lt;/p&gt;

&lt;p&gt;This is especially common among:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Agencies&lt;/li&gt;
&lt;li&gt;Startups&lt;/li&gt;
&lt;li&gt;Operations teams&lt;/li&gt;
&lt;li&gt;Marketing teams&lt;/li&gt;
&lt;li&gt;Internal automation groups&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These teams often have technical knowledge, but they do not necessarily want infrastructure management to become a recurring responsibility.&lt;/p&gt;

&lt;p&gt;The goal is to build workflows.&lt;/p&gt;

&lt;p&gt;Not maintain servers.&lt;/p&gt;

&lt;p&gt;That is why managed platforms continue to gain attention.&lt;/p&gt;

&lt;p&gt;Instead of spending hours configuring servers, backups, monitoring, SSL, and updates, teams can start building automations immediately.&lt;/p&gt;

&lt;p&gt;For example, platforms such as &lt;a href="https://www.agntable.com" rel="noopener noreferrer"&gt;Agntable&lt;/a&gt; provide &lt;a href="https://dev.tomanaged%20n8n%20hosting"&gt;managed n8n hosting&lt;/a&gt; with infrastructure, monitoring, backups, SSL, and maintenance already handled. This lets teams focus on workflows rather than server operations.&lt;/p&gt;

&lt;p&gt;Whether that tradeoff is worth it depends on how much infrastructure work your team wants to own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reliability matters more than price
&lt;/h2&gt;

&lt;p&gt;One mistake many teams make is choosing hosting based entirely on monthly cost.&lt;/p&gt;

&lt;p&gt;A $10 VPS can look attractive.&lt;/p&gt;

&lt;p&gt;But the server bill is rarely the biggest expense.&lt;/p&gt;

&lt;p&gt;The larger cost is usually time.&lt;/p&gt;

&lt;p&gt;How much time is spent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managing updates&lt;/li&gt;
&lt;li&gt;Troubleshooting issues&lt;/li&gt;
&lt;li&gt;Monitoring uptime&lt;/li&gt;
&lt;li&gt;Maintaining backups&lt;/li&gt;
&lt;li&gt;Recovering from failures&lt;/li&gt;
&lt;li&gt;Securing the environment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a developer running personal automations, that cost may be acceptable.&lt;/p&gt;

&lt;p&gt;For a business team, the calculation is often different.&lt;/p&gt;

&lt;p&gt;If an automation platform supports revenue-generating workflows, employee productivity, or customer-facing processes, reliability quickly becomes more valuable than saving a few dollars per month.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI workflows make hosting more important
&lt;/h2&gt;

&lt;p&gt;The rise of AI automation has made hosting decisions even more significant.&lt;/p&gt;

&lt;p&gt;Many n8n workflows now connect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LLM providers&lt;/li&gt;
&lt;li&gt;Vector databases&lt;/li&gt;
&lt;li&gt;Retrieval systems&lt;/li&gt;
&lt;li&gt;Internal APIs&lt;/li&gt;
&lt;li&gt;CRM platforms&lt;/li&gt;
&lt;li&gt;Support tools&lt;/li&gt;
&lt;li&gt;Content generation systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These workflows are often more resource-intensive than traditional automations.&lt;/p&gt;

&lt;p&gt;They may run longer.&lt;/p&gt;

&lt;p&gt;They may process more data.&lt;/p&gt;

&lt;p&gt;They may involve multiple API calls.&lt;/p&gt;

&lt;p&gt;They may become central to business operations.&lt;/p&gt;

&lt;p&gt;As AI adoption increases, infrastructure quality becomes increasingly important.&lt;/p&gt;

&lt;p&gt;A workflow that generates customer reports, enriches leads, summarizes support tickets, or powers internal knowledge systems needs dependable hosting.&lt;/p&gt;

&lt;p&gt;This is where many teams discover that hosting is not just a technical detail.&lt;/p&gt;

&lt;p&gt;It is part of the workflow architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the right option
&lt;/h2&gt;

&lt;p&gt;There is no universal best hosting provider.&lt;/p&gt;

&lt;p&gt;The best choice depends on your goals.&lt;/p&gt;

&lt;p&gt;If you want maximum control and have infrastructure experience, self-hosting on a VPS can be excellent.&lt;/p&gt;

&lt;p&gt;If you want the official hosted experience, n8n Cloud is a strong option.&lt;/p&gt;

&lt;p&gt;If you want the flexibility of n8n without ongoing server maintenance, managed hosting may provide the best balance.&lt;/p&gt;

&lt;p&gt;The important thing is understanding what you are actually buying.&lt;/p&gt;

&lt;p&gt;You are not only buying CPU and RAM.&lt;/p&gt;

&lt;p&gt;You are buying responsibility.&lt;/p&gt;

&lt;p&gt;The less responsibility you want, the more value hosted and managed options tend to provide.&lt;/p&gt;

&lt;p&gt;The more control you want, the more self-hosting makes sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;By 2026, the conversation around n8n hosting is no longer just about where the software runs.&lt;/p&gt;

&lt;p&gt;It is about how much infrastructure your team wants to own.&lt;/p&gt;

&lt;p&gt;The cheapest server is not always the best option.&lt;/p&gt;

&lt;p&gt;The most flexible platform is not always the right fit.&lt;/p&gt;

&lt;p&gt;And the official cloud offering is not automatically the best choice for every workflow.&lt;/p&gt;

&lt;p&gt;The right hosting environment is the one that allows your team to spend more time building automation and less time worrying about the systems underneath it.&lt;/p&gt;

&lt;p&gt;Because at the end of the day, nobody adopts n8n because they want to manage servers.&lt;/p&gt;

&lt;p&gt;They adopt n8n because they want workflows that work.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>devops</category>
      <category>docker</category>
    </item>
    <item>
      <title>Self-Hosting Hermes Agent: What Developers Should Know First</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Tue, 09 Jun 2026 11:57:51 +0000</pubDate>
      <link>https://dev.to/klarvpn/self-hosting-hermes-agent-what-developers-should-know-first-hna</link>
      <guid>https://dev.to/klarvpn/self-hosting-hermes-agent-what-developers-should-know-first-hna</guid>
      <description>&lt;p&gt;Hermes Agent is the kind of AI tool that becomes more interesting once it moves beyond a simple local experiment.&lt;/p&gt;

&lt;p&gt;Running an AI assistant on your laptop is useful for testing. You can install it, connect a model provider, try a few prompts, and understand how it behaves. But the real value appears when the assistant becomes persistent: always available, connected to messaging tools, able to use memory, and ready to support real workflows.&lt;/p&gt;

&lt;p&gt;That shift changes the problem.&lt;/p&gt;

&lt;p&gt;At the beginning, the question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Can I install Hermes Agent?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Later, the question becomes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Can I run Hermes Agent reliably as an always-on service?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Those are very different problems.&lt;/p&gt;

&lt;p&gt;This article looks at the developer side of self-hosting Hermes Agent: what local setup is good for, why a VPS changes the maintenance burden, what infrastructure details matter, and when managed hosting becomes the more practical route.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start local, but do not confuse local with production
&lt;/h2&gt;

&lt;p&gt;A local Hermes Agent setup is the best place to begin.&lt;/p&gt;

&lt;p&gt;It gives you a safe environment to test the assistant, configure a model provider, explore commands, and understand how memory and tools behave. For developers, this is the right first step because it keeps the feedback loop short. You can break things, reset things, and learn without worrying about uptime or public exposure.&lt;/p&gt;

&lt;p&gt;But a local setup has obvious limits.&lt;/p&gt;

&lt;p&gt;Your laptop sleeps. Your network changes. Your terminal session ends. Your assistant is not always reachable. Messaging gateways are harder to rely on. Scheduled or long-running tasks become fragile.&lt;/p&gt;

&lt;p&gt;That is fine for learning. It is not ideal for a persistent AI assistant.&lt;/p&gt;

&lt;p&gt;A local installation proves that Hermes works. It does not prove that Hermes is ready to support daily workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  The VPS step changes everything
&lt;/h2&gt;

&lt;p&gt;Once Hermes Agent moves to a VPS, it becomes a real service.&lt;/p&gt;

&lt;p&gt;That has clear benefits. The assistant can run continuously. It can stay connected to messaging platforms. It can survive your laptop shutting down. It can become part of your daily workflow instead of something you launch manually.&lt;/p&gt;

&lt;p&gt;But the VPS also changes your responsibilities.&lt;/p&gt;

&lt;p&gt;Now you are not only using Hermes Agent. You are operating it.&lt;/p&gt;

&lt;p&gt;You need to think about Linux users, SSH access, firewall rules, environment variables, service management, logs, backups, updates, API keys, and monitoring. These are not unusual tasks for developers, but they are still real tasks.&lt;/p&gt;

&lt;p&gt;A VPS gives control. It also gives ownership.&lt;/p&gt;

&lt;p&gt;That ownership is the part many people underestimate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Always-on agents need service management
&lt;/h2&gt;

&lt;p&gt;Running Hermes Agent manually in a terminal is fine for testing, but it is not enough for a persistent assistant.&lt;/p&gt;

&lt;p&gt;A real always-on setup should continue running after SSH disconnects. It should restart after crashes. It should come back after server reboots. It should provide logs when something goes wrong.&lt;/p&gt;

&lt;p&gt;This is where service management becomes important.&lt;/p&gt;

&lt;p&gt;For Linux servers, that usually means running the gateway as a systemd service. Once Hermes is managed by systemd, it behaves less like a script and more like an actual background service.&lt;/p&gt;

&lt;p&gt;That matters because an AI assistant connected to messaging tools should not disappear just because an SSH session ended.&lt;/p&gt;

&lt;p&gt;The moment users depend on the agent, process supervision becomes part of the product experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Messaging gateways are convenient, but they increase risk
&lt;/h2&gt;

&lt;p&gt;Hermes Agent becomes much more useful when it is connected to tools like Telegram, Slack, Discord, or other messaging platforms.&lt;/p&gt;

&lt;p&gt;A chat-connected agent feels natural. You can interact with it from the place where you already communicate. You do not need to open a terminal every time. The assistant becomes more accessible and more useful throughout the day.&lt;/p&gt;

&lt;p&gt;But messaging gateways also create security concerns.&lt;/p&gt;

&lt;p&gt;A bot token is not just a configuration value. It is access. If the token is exposed, someone may be able to interact with the assistant. If allowed users are not restricted properly, the assistant may respond to people who should not have access. If the agent has powerful tools enabled, that risk becomes more serious.&lt;/p&gt;

&lt;p&gt;This is why gateway configuration should be treated carefully.&lt;/p&gt;

&lt;p&gt;A persistent agent should only respond to trusted users. Sensitive actions should require approval. Tokens should be protected. Logs should be checked. The convenience of messaging should not come at the cost of control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory makes backups more important than usual
&lt;/h2&gt;

&lt;p&gt;For many AI tools, losing a local install is annoying but recoverable.&lt;/p&gt;

&lt;p&gt;For a memory-aware assistant, it can be more serious.&lt;/p&gt;

&lt;p&gt;Hermes Agent becomes more valuable as it accumulates useful context, preferences, sessions, skills, and configuration. That history is part of what makes the assistant feel personal and productive.&lt;/p&gt;

&lt;p&gt;If that data is lost, you do not only lose files. You lose the context that made the assistant useful.&lt;/p&gt;

&lt;p&gt;That is why backups should be part of the setup from the beginning, not something added later.&lt;/p&gt;

&lt;p&gt;A serious self-hosted setup should back up the Hermes configuration and memory directory regularly. It should also sync those backups away from the VPS. A backup stored only on the same server is better than nothing, but it does not protect you from server failure, disk issues, account problems, or accidental deletion.&lt;/p&gt;

&lt;p&gt;Self-hosting gives data ownership. Backups are the responsibility that comes with that ownership.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model providers are part of the infrastructure
&lt;/h2&gt;

&lt;p&gt;Hermes Agent needs a model provider or local model setup to function.&lt;/p&gt;

&lt;p&gt;That decision affects performance, cost, privacy, and reliability.&lt;/p&gt;

&lt;p&gt;Hosted providers are usually easier to start with. They give access to strong models without requiring local GPU infrastructure. The tradeoff is cost and dependency on external APIs.&lt;/p&gt;

&lt;p&gt;Local models can reduce reliance on external providers, but they come with hardware and quality tradeoffs. Running local models well may require more setup, more tuning, and better machine resources.&lt;/p&gt;

&lt;p&gt;For a casual test, model choice may not matter much. For an always-on assistant, it matters a lot.&lt;/p&gt;

&lt;p&gt;The agent may run many requests throughout the day. Tool definitions, system prompts, long context, and repeated interactions can increase token usage. That means cost visibility matters.&lt;/p&gt;

&lt;p&gt;A self-hosted assistant should not be treated as “free” just because the software is open source. The server may be cheap, but model usage can still become the larger cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Self-hosting is not only about installation
&lt;/h2&gt;

&lt;p&gt;Many tutorials focus on the first successful run. That is useful, but it can create the wrong impression.&lt;/p&gt;

&lt;p&gt;The first successful run is not the finish line.&lt;/p&gt;

&lt;p&gt;A better way to think about self-hosting Hermes Agent is in stages.&lt;/p&gt;

&lt;p&gt;First, you prove the assistant works locally. Then you move it to a VPS for persistence. Then you configure the model provider and messaging gateway. Then you make it always-on. Then you add backups, security, monitoring, and update routines.&lt;/p&gt;

&lt;p&gt;The work does not end when the command succeeds.&lt;/p&gt;

&lt;p&gt;That is where the difference between a demo and a reliable assistant becomes clear.&lt;/p&gt;

&lt;p&gt;A demo only needs to work once. A persistent assistant needs to keep working.&lt;/p&gt;

&lt;h2&gt;
  
  
  The maintenance burden is real
&lt;/h2&gt;

&lt;p&gt;A self-hosted Hermes Agent setup can be rewarding, especially for developers who enjoy understanding the system deeply. You get control over the server, configuration, model routing, gateways, files, and updates.&lt;/p&gt;

&lt;p&gt;But that control has a cost.&lt;/p&gt;

&lt;p&gt;You need to maintain the server. You need to handle updates. You need to monitor logs. You need to protect secrets. You need to keep backups. You need to check that the gateway is alive. You need to watch model costs. You need to fix things when they break.&lt;/p&gt;

&lt;p&gt;None of this makes self-hosting a bad option.&lt;/p&gt;

&lt;p&gt;It simply means self-hosting should be chosen intentionally.&lt;/p&gt;

&lt;p&gt;The wrong reason to self-host is “it looks cheaper.” The better reason is “I want control, and I am comfortable owning the maintenance.”&lt;/p&gt;

&lt;h2&gt;
  
  
  When managed hosting makes sense
&lt;/h2&gt;

&lt;p&gt;Managed hosting becomes attractive when the goal is to use Hermes Agent, not maintain the server around it.&lt;/p&gt;

&lt;p&gt;This is especially true for users who want an always-on assistant with memory, messaging access, and reliable availability but do not want to spend time managing Linux services, backups, security hardening, and troubleshooting.&lt;/p&gt;

&lt;p&gt;The manual path is worth understanding because it shows what is happening behind the scenes. &lt;a href="https://agntable.com/" rel="noopener noreferrer"&gt;Agntable&lt;/a&gt; has a detailed guide on &lt;a href="https://www.agntable.com/blog/how-to-self-host-hermes-agent" rel="noopener noreferrer"&gt;how to self-host Hermes Agent&lt;/a&gt;, covering the local setup, VPS path, model configuration, messaging gateway, systemd service, backups, security, and the self-hosting versus managed-hosting decision.&lt;/p&gt;

&lt;p&gt;That guide is helpful even for users who later choose managed hosting, because it makes the tradeoff visible.&lt;/p&gt;

&lt;p&gt;Managed hosting does not remove the value of Hermes Agent. It removes much of the infrastructure work around it.&lt;/p&gt;

&lt;p&gt;For teams, agencies, operators, and non-infrastructure-focused builders, that can be the more practical route.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical decision framework
&lt;/h2&gt;

&lt;p&gt;The self-hosting decision should start with the role Hermes Agent will play.&lt;/p&gt;

&lt;p&gt;For learning and experimentation, local setup is enough. It is fast, low-risk, and flexible.&lt;/p&gt;

&lt;p&gt;For personal always-on usage, a VPS makes sense when you are comfortable with server maintenance.&lt;/p&gt;

&lt;p&gt;For business workflows, team usage, or client-facing setups, the infrastructure burden deserves more serious thought.&lt;/p&gt;

&lt;p&gt;The more important the assistant becomes, the more important reliability becomes.&lt;/p&gt;

&lt;p&gt;A broken local experiment is a minor inconvenience. A broken always-on assistant connected to work tools can disrupt real workflows.&lt;/p&gt;

&lt;p&gt;That is the point where managed hosting becomes worth considering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Hermes Agent is interesting because it points toward the future of AI assistants: persistent, memory-aware, tool-connected systems that can support real workflows.&lt;/p&gt;

&lt;p&gt;But the more useful the assistant becomes, the more important the hosting model becomes.&lt;/p&gt;

&lt;p&gt;Local setup is great for learning. VPS hosting gives you control and persistence. Managed hosting reduces the maintenance burden and lets you focus on using the assistant instead of operating the server.&lt;/p&gt;

&lt;p&gt;The right choice depends on what you want to own.&lt;/p&gt;

&lt;p&gt;Some developers want to own the full stack.&lt;/p&gt;

&lt;p&gt;Others want the agent to stay online while they focus on building workflows, automating tasks, and improving how they work.&lt;/p&gt;

&lt;p&gt;Both paths are valid.&lt;/p&gt;

&lt;p&gt;The important thing is to choose deliberately, because an always-on AI assistant is not just an app.&lt;/p&gt;

&lt;p&gt;It is infrastructure.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>docker</category>
      <category>devops</category>
    </item>
    <item>
      <title>Hermes Agent and the Shift From Chatbots to Personal AI Runtimes</title>
      <dc:creator>KlarVPN</dc:creator>
      <pubDate>Fri, 05 Jun 2026 16:57:49 +0000</pubDate>
      <link>https://dev.to/klarvpn/hermes-agent-and-the-shift-from-chatbots-to-personal-ai-runtimes-3kcg</link>
      <guid>https://dev.to/klarvpn/hermes-agent-and-the-shift-from-chatbots-to-personal-ai-runtimes-3kcg</guid>
      <description>&lt;p&gt;AI assistants are moving into a new phase.&lt;/p&gt;

&lt;p&gt;For the last few years, most AI products have followed the same pattern: the user opens a chat interface, writes a prompt, receives a response, and then manually moves that response into the real workflow.&lt;/p&gt;

&lt;p&gt;That model is useful, but it has a ceiling.&lt;/p&gt;

&lt;p&gt;A chatbot can explain what to do.&lt;br&gt;
An AI agent should help do it.&lt;/p&gt;

&lt;p&gt;That is why systems like Hermes Agent are worth paying attention to. Hermes Agent represents a broader shift toward personal AI assistants that can combine reasoning, memory, tools, workflow context, and repeated user feedback into something more useful than a single chat session.&lt;/p&gt;

&lt;p&gt;For developers, the interesting part is not only the assistant itself.&lt;/p&gt;

&lt;p&gt;The interesting part is the architecture behind it.&lt;/p&gt;
&lt;h2&gt;
  
  
  The problem with normal AI chat
&lt;/h2&gt;

&lt;p&gt;Most AI chat tools are stateless by default or only lightly personalized.&lt;/p&gt;

&lt;p&gt;They can generate useful answers, but they often lack deep awareness of the user’s tools, routines, data, permissions, and workflow patterns.&lt;/p&gt;

&lt;p&gt;For example, you can ask a chatbot to help plan a product launch. It may produce a solid plan. But after that, the user still needs to create tasks, update project boards, draft emails, schedule meetings, notify the team, check analytics, and monitor progress.&lt;/p&gt;

&lt;p&gt;The intelligence is there, but the execution layer is missing.&lt;/p&gt;

&lt;p&gt;That is the gap AI agents are trying to close.&lt;/p&gt;

&lt;p&gt;A useful assistant should not only answer a question. It should understand the goal, identify the steps, access the right tools, prepare actions, ask for approval where necessary, and help complete the workflow.&lt;/p&gt;

&lt;p&gt;This is why the term “AI agent” keeps showing up in developer conversations. It is not just a branding upgrade from “chatbot.” It describes a different kind of system.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Hermes Agent represents
&lt;/h2&gt;

&lt;p&gt;Hermes Agent is part of the growing category of personal AI agents designed to operate closer to a user’s daily work.&lt;/p&gt;

&lt;p&gt;Instead of being limited to a chat window, the idea is to give the assistant access to tools, memory, device context, apps, and workflows. The assistant can then become more useful over time because it has more context about how the user works and what actions usually follow certain requests.&lt;/p&gt;

&lt;p&gt;That is the important distinction.&lt;/p&gt;

&lt;p&gt;A normal chatbot treats most prompts as isolated events.&lt;/p&gt;

&lt;p&gt;A personal AI agent tries to treat requests as part of a larger workflow.&lt;/p&gt;

&lt;p&gt;The assistant may need to understand what the user is trying to accomplish, which tools are relevant, what information is needed, whether the action is safe, and whether human confirmation is required before execution.&lt;/p&gt;

&lt;p&gt;From a developer perspective, this makes Hermes Agent interesting because it points toward a future where AI assistants behave more like personal runtimes than simple chat interfaces.&lt;/p&gt;
&lt;h2&gt;
  
  
  What does “self-improving” actually mean?
&lt;/h2&gt;

&lt;p&gt;The phrase “self-improving AI assistant” can sound vague, so it is worth making it practical.&lt;/p&gt;

&lt;p&gt;In most real-world systems, self-improvement does not mean the agent is freely rewriting its own foundation model. It usually means the system improves through memory, feedback, workflow history, tool results, and user corrections.&lt;/p&gt;

&lt;p&gt;A self-improving assistant might learn that the user prefers short meeting summaries, that certain calendar events require preparation notes, that specific contacts should be included in follow-ups, or that some actions should always require approval.&lt;/p&gt;

&lt;p&gt;It might also learn from failed attempts. If the assistant chooses the wrong tool, receives a correction, or produces an output the user edits repeatedly, the system can use that feedback to improve future behavior.&lt;/p&gt;

&lt;p&gt;In practical terms, self-improvement is less about an AI becoming independently smarter and more about an assistant becoming better adapted to a specific user or workflow.&lt;/p&gt;

&lt;p&gt;That is still powerful.&lt;/p&gt;

&lt;p&gt;Generic intelligence is useful, but workflow-aware intelligence is often more valuable.&lt;/p&gt;
&lt;h2&gt;
  
  
  The core pieces of a personal AI agent
&lt;/h2&gt;

&lt;p&gt;A personal AI agent needs more than an LLM.&lt;/p&gt;

&lt;p&gt;The model is only one part of the system. To become useful in real workflows, the agent needs access to tools, memory, execution logic, permissions, and a runtime environment.&lt;/p&gt;

&lt;p&gt;A simplified architecture might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User request
   ↓
Intent understanding
   ↓
Context and memory lookup
   ↓
Tool selection
   ↓
Action planning
   ↓
Human approval if needed
   ↓
Execution
   ↓
Result logging and feedback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why agent systems are harder than chatbot interfaces.&lt;/p&gt;

&lt;p&gt;The assistant has to decide what the user means, identify what information is missing, choose the right tool, execute safely, handle errors, and remember what happened.&lt;/p&gt;

&lt;p&gt;Each step introduces complexity.&lt;/p&gt;

&lt;p&gt;If the agent chooses the wrong tool, the workflow fails. If it has too much access, it becomes risky. If it has no memory, it feels repetitive. If it has memory without boundaries, it creates privacy concerns. If it executes actions without approval, users may not trust it.&lt;/p&gt;

&lt;p&gt;Good AI agent design is not just about model quality.&lt;/p&gt;

&lt;p&gt;It is about system design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tool access changes everything
&lt;/h2&gt;

&lt;p&gt;The biggest difference between a chatbot and an agent is tool access.&lt;/p&gt;

&lt;p&gt;A chatbot can generate a response.&lt;br&gt;
An agent can interact with systems.&lt;/p&gt;

&lt;p&gt;That might include calendars, email, messaging apps, databases, dashboards, APIs, file systems, CRMs, task managers, browsers, cloud services, or internal tools.&lt;/p&gt;

&lt;p&gt;This is where AI agents become useful for developers and teams. Instead of asking an AI assistant to explain a process, the assistant can participate in the process.&lt;/p&gt;

&lt;p&gt;For example, an agent could summarize a support thread, check the customer record, draft a response, suggest a priority, and create a follow-up task. Another agent could monitor a deployment issue, summarize logs, open a ticket, and notify the right channel.&lt;/p&gt;

&lt;p&gt;The key point is that the assistant becomes part of the workflow instead of staying outside it.&lt;/p&gt;

&lt;p&gt;But tool access also raises the stakes.&lt;/p&gt;

&lt;p&gt;Once an agent can act on behalf of a user, permissions, security, audit logs, and approval flows become essential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory is useful, but dangerous without boundaries
&lt;/h2&gt;

&lt;p&gt;Memory is one of the features that makes a personal AI assistant feel genuinely helpful.&lt;/p&gt;

&lt;p&gt;Without memory, the user has to repeat preferences, context, goals, and workflow details again and again. With memory, the assistant can become more personalized and efficient.&lt;/p&gt;

&lt;p&gt;But memory needs boundaries.&lt;/p&gt;

&lt;p&gt;A useful agent should remember the right things and forget or protect the wrong things. It should be clear what the system knows, why it knows it, and how the user can correct or remove it.&lt;/p&gt;

&lt;p&gt;This is especially important for work-related agents.&lt;/p&gt;

&lt;p&gt;An assistant connected to business systems may encounter customer data, private notes, credentials, internal plans, financial information, or sensitive communications. If memory is handled poorly, the assistant becomes a risk.&lt;/p&gt;

&lt;p&gt;That is why self-improving agents need strong control layers.&lt;/p&gt;

&lt;p&gt;The assistant should learn from the user, but the user should remain in control of what it learns and how it acts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Human approval is not a weakness
&lt;/h2&gt;

&lt;p&gt;Some people imagine AI agents as fully autonomous workers that complete everything without human involvement.&lt;/p&gt;

&lt;p&gt;That may sound impressive, but in many real workflows, full autonomy is not the safest or most useful design.&lt;/p&gt;

&lt;p&gt;A better model is controlled autonomy.&lt;/p&gt;

&lt;p&gt;The agent can research, prepare, summarize, organize, and recommend. But when the action is sensitive, expensive, public, destructive, or irreversible, the system should ask for approval.&lt;/p&gt;

&lt;p&gt;This is not a limitation.&lt;/p&gt;

&lt;p&gt;It is how trust is built.&lt;/p&gt;

&lt;p&gt;A developer would not want an agent randomly deleting files, changing production settings, sending business emails, modifying customer records, or making purchases without confirmation.&lt;/p&gt;

&lt;p&gt;The best agents will understand when to act and when to ask.&lt;/p&gt;

&lt;p&gt;That distinction matters more than raw autonomy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why infrastructure matters
&lt;/h2&gt;

&lt;p&gt;Hermes Agent and similar systems are often discussed from the user experience side, but the infrastructure side is just as important.&lt;/p&gt;

&lt;p&gt;An AI agent needs to run somewhere. It needs access to models. It needs secure storage. It needs authentication. It needs tool integrations. It needs logs. It needs monitoring. It needs update handling. It needs failure recovery.&lt;/p&gt;

&lt;p&gt;This is where many agent projects become difficult.&lt;/p&gt;

&lt;p&gt;A prototype can be built quickly. A reliable agent system takes more work.&lt;/p&gt;

&lt;p&gt;Once an assistant becomes part of daily work, it cannot be treated like a temporary experiment. If it handles real tasks, the system needs to be available, secure, observable, and maintainable.&lt;/p&gt;

&lt;p&gt;That is why platforms like &lt;a href="https://www.agntable.com/" rel="noopener noreferrer"&gt;Agntable&lt;/a&gt; are useful for teams experimenting with open-source AI agents and automation tools. They help reduce the infrastructure burden so teams can focus on building useful workflows instead of spending most of their time managing servers and deployment details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where developers should focus
&lt;/h2&gt;

&lt;p&gt;The next phase of AI assistants will not be defined only by who has the best prompt.&lt;/p&gt;

&lt;p&gt;It will be defined by who builds the best systems around the model.&lt;/p&gt;

&lt;p&gt;For developers, that means thinking about memory design, tool permissions, retries, logs, approval steps, error handling, data privacy, and deployment.&lt;/p&gt;

&lt;p&gt;A good AI agent should be able to answer questions, but that is only the beginning.&lt;/p&gt;

&lt;p&gt;It should also be able to connect context with action.&lt;/p&gt;

&lt;p&gt;It should know when it has enough information and when it needs to ask a follow-up question.&lt;/p&gt;

&lt;p&gt;It should handle tool failures gracefully.&lt;/p&gt;

&lt;p&gt;It should make its actions visible.&lt;/p&gt;

&lt;p&gt;It should improve from feedback without becoming unpredictable.&lt;/p&gt;

&lt;p&gt;Those are product and engineering problems, not just AI problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hermes Agent is part of a bigger pattern
&lt;/h2&gt;

&lt;p&gt;Whether Hermes Agent becomes a dominant assistant or one of many experiments, the pattern behind it is important.&lt;/p&gt;

&lt;p&gt;AI assistants are becoming more personal, more connected, and more action-oriented.&lt;/p&gt;

&lt;p&gt;They are moving from chat windows into devices, apps, workflows, and operating systems.&lt;/p&gt;

&lt;p&gt;They are expected to remember context, use tools, adapt to users, and help complete tasks.&lt;/p&gt;

&lt;p&gt;This shift will create better productivity tools, but it will also create new engineering challenges.&lt;/p&gt;

&lt;p&gt;Developers will need to think carefully about where agents run, what they can access, how they are monitored, how they recover from mistakes, and how users stay in control.&lt;/p&gt;

&lt;p&gt;The future of AI assistants is not just better conversation.&lt;/p&gt;

&lt;p&gt;It is safer execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Hermes Agent is interesting because it reflects where AI assistants are heading.&lt;/p&gt;

&lt;p&gt;The next generation of assistants will not only generate text. They will understand tasks, use tools, remember context, request approval, and improve through repeated interaction.&lt;/p&gt;

&lt;p&gt;That is a much more useful model than a standalone chatbot.&lt;/p&gt;

&lt;p&gt;It is also much harder to build.&lt;/p&gt;

&lt;p&gt;The best AI agents will not be the ones that act the fastest or claim the most autonomy. They will be the ones that combine intelligence with trust, workflow awareness, and reliable infrastructure.&lt;/p&gt;

&lt;p&gt;For developers, that is the real opportunity.&lt;/p&gt;

&lt;p&gt;Not just building assistants that sound smart.&lt;/p&gt;

&lt;p&gt;Building assistants that can safely help people get work done.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>automation</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
