Skip to content
VPNDetection

Fail open vs fail closed: when your VPN check doesn't answer

What an app should do when a VPN check times out or fails: we broke our API two ways in an Express app, then gave each kind of route a default.

Published 7 min read

On this page
  1. How often the check doesn't answer
  2. Breaking it two ways
  3. What the log says
  4. Fail open or fail closed, route by route
  5. The base client's defaults are for batch jobs
  6. Take the check off the request path where you can
  7. A paid plan's key, and a wrong one

Every check on a request path needs an answer to one question: what happens when it doesn't answer? Most apps answer it by accident, with whatever their HTTP client does by default. On December 1, 2026, our own Node.js client, on its defaults, held a lookup for 34.5 seconds against an API that never answered, then raised an error. Our Express middleware, on its defaults, gave up after 2.5 seconds and let the visitor through. Neither is right for every route.

This post measures how often the check fails, breaks it in an Express app, and gives each kind of route its own default.

How often the check doesn't answer

The time our edge spent on each successful lookup, from the request arriving to the answer leaving, over the 28 days to November 13, 2026:

PercentileTime at our edge
Median6 ms
95th16 ms
99th58 ms
99.9th228 ms

No lookup in those 28 days got a server error. A few requests got no response at all, and each was a client that hung up before it had finished sending its request. That's what reached our edge. An outage that kept requests from reaching it would show on our status page, which keeps the history.

The rest of the wait is the network. Our API runs in Finland (DPA), and a cold HTTPS call makes three round trips to it before the answer starts back: one to connect, one for TLS and one for the request. A call over a connection already open makes one. From a server in Helsinki, next door to the API, the median of three cold calls was 22 ms:

console
$ curl -s -o /dev/null https://api.vpndetection.io/45.134.140.130 \
    -w 'connect %{time_connect}s  tls %{time_appconnect}s  total %{time_total}s\n'
connect 0.002094s  tls 0.019026s  total 0.022186s

Connecting took 2.1 ms, one round trip from there. Most of the 22 ms was the TLS handshake's own work. Over a connection already open, the median was 4 ms. From farther away, each round trip adds your distance to Finland: run the command from your own server to see it.

The other failures an app can meet are its own: a burst (429 with Retry-After) and the network between you and us. The rate limits page says how to read a 429.

Breaking it two ways

The app has three routes, each failing its own way. It uses our Express middleware, vpndetection-express, which fails open unless told otherwise, and one client for all three, so they share its cache:

js
import express from 'express';
import { VPNDetection } from 'vpndetection';
import { vpndetection } from 'vpndetection-express';

const app = express();
app.set('trust proxy', 'loopback');

// One client, so every route shares one cache: an hour per address.
const client = new VPNDetection();

function logFailure(req) {
    const { ip, error } = req.vpndetection;
    console.warn(`vpn check failed for ${ip}: ${error.kind}: ${error.message}`);
}

// Pages: fail open, and fast.
app.get('/', vpndetection({ client, timeoutMs: 1000 }), (req, res) => {
    if (req.vpndetection.error) logFailure(req);
    res.json({ page: 'home' });
});

// Signup: fail open, into the same check a flagged address gets.
app.post('/signup', vpndetection({ client }), (req, res) => {
    const { result, error } = req.vpndetection;
    if (error) {
        logFailure(req);
        return res.json({ decision: 'verify', reason: 'no answer' });
    }
    // A private address means a proxy we don't trust hid the visitor.
    if (result.isBogon || result.isVpn || result.isTor) {
        return res.json({ decision: 'verify', reason: 'flagged' });
    }
    res.json({ decision: 'allow' });
});

// Payouts: fail closed. No answer, no payout, and the answer says why.
const payoutCheck = vpndetection({
    client,
    timeoutMs: 3000,
    retries: 1,
    failClosed: true,
    blockCondition: [{ isVpn: true }, { isTor: true }, { isBogon: true }],
    onBlocked: (req, res, lookup) => {
        if (lookup.error) {
            logFailure(req);
            res.set('Retry-After', '60');
            return res.status(503).json({ error: 'payouts paused, retry later' });
        }
        res.status(403).json({ error: 'payouts need a direct connection' });
    },
});
app.post('/payout', payoutCheck, (req, res) => res.json({ decision: 'paid' }));

app.listen(3000);

failClosed turns a failed lookup into a block, and onBlocked tells the two apart: lookup.error is set only when the lookup failed. The app acts on isVpn and isTor, which the free plan answers. Which flags a route should act on is a decision of its own. This post is about what to do when none come back.

We ran it on December 1, 2026, with Node.js 22.23, Express 5.3.0, vpndetection 6.0.0 and vpndetection-express 3.0.0, and every output below comes from those releases. Each request was sent from loopback with the address of Mullvad's Atlanta server, from Mullvad's own list, in X-Forwarded-For:

bash
for r in 'GET /' 'POST /signup' 'POST /payout'; do
    curl -s -X "${r% *}" -H 'X-Forwarded-For: 45.134.140.130' \
        -w ' %{http_code} %{time_total}s\n' "localhost:3000${r#* }"
done

To break the API, we pointed its hostname elsewhere in the app's hosts file: at 127.0.0.1, where nothing listens, for an API that refuses connections, and at 192.0.2.1, an address set aside for documentation that nothing answers, for one that never answers. Times are the median of three runs:

What happenedGET /, fails openPOST /signup, fails open to a checkPOST /payout, fails closed
API answered200 in 0.04 sverify, flagged403
API refused connections200verify, no answer503 after 1.0 s
API never answered200 after 1.0 sverify, no answer, after 2.5 s503 after 7.0 s

With the API answering, signup and payout took about a millisecond each: the page's lookup had already put Mullvad's answer in the shared cache. A failure is never cached, so the next request asks again.

Where the API never answered, the second of the three runs printed:

console
{"page":"home"} 200 1.003447s
{"decision":"verify","reason":"no answer"} 200 2.502374s
{"error":"payouts paused, retry later"} 503 7.002924s

The payout waited 3 seconds, 1 more before its one retry, then 3 again. Where connections were refused, each attempt failed at once, so the retry cost only the 1-second wait.

A bar chart of how long a visitor waited when our API never answered, measured on December 1, 2026: a page with a 1-second timeout waited 1.0 s, a signup on the middleware's default 2.5 s, a payout with a 3-second timeout and one retry 7.0 s, and the base client on its defaults 34.5 s.

What the log says

The app logged, for refused connections and then an API that never answered:

console
vpn check failed for 45.134.140.130: network: no response from the API
vpn check failed for 45.134.140.130: network: request timed out after 2500ms

Read error.kind and act on it:

  • network or server_error: the API or the network to it. Fail the way the route says.
  • rate_limited: a burst. A route with a retry waits out Retry-After, however long it is, and asks again, so a payout can wait well past 7 seconds. One with none fails the way the route says.
  • bad_request: no usable client address on the request, usually your proxy settings. Fail the way the route says, and fix them.

Fail open or fail closed, route by route

Decide by what each mistake costs. A missed VPN on a page costs nothing, and a 3-second wait during an outage costs every visitor. A missed VPN on a payout sends money that doesn't come back, and a refused payout can wait a minute.

RouteWhen the check doesn't answerTimeout and retries
Pages, search, contentFail open1 s or less, none
Sign-in for existing accountsFail open: the password is the checkThe middleware's 2.5 s, none
Signup, free trials, couponsFail open, into the check a flagged address gets: email or phone verification2.5 s, none
CheckoutFail open, into 3-D Secure2.5 s, none
Payouts, withdrawals, gift cardsFail closed, with a 503, Retry-After and words saying it's paused3 s, one
Playback licensed by countryFail closed: the license doesn't bend for an outage3 s, one
Signup during a bot attackFail closed, until the attack ends2.5 s, none

A route that fails open into a check gets the step-up whether the lookup said VPN or said nothing. Our UK Online Safety Act post does the same with age assurance: a failed lookup is not an answer.

The base client's defaults are for batch jobs

The base client, VPNDetection, waits 30 seconds per attempt and retries twice, which suits a nightly job scoring a table of signups. In front of a visitor it doesn't. Against 192.0.2.1, where nothing answers, one lookup on those defaults took 34.5 seconds in each of three runs: three attempts of 10.5 seconds, each cut short by Node's own connect timeout before the client's 30 seconds came up, with 1 and 2 seconds between them. Against an API that accepted connections and then stalled, the 30 seconds would apply instead.

Each of our middleware packages has its own defaults for the request path: 2.5 seconds, no retry, and fail open. Pass the timeout per route, as the app above does, rather than changing the client's.

Take the check off the request path where you can

  • Look up once and store the answer. A signup's verdict goes on the account. Sign-ins and later requests read it, and nothing waits on us.
  • Share one client. Its cache keeps up to 10,000 answers in memory, each for an hour. Two routes asking about one address at once share one lookup, made with the settings of the route that asked first.
  • Above a few million distinct addresses a day, look up from a copy of the databases on your own servers. A lookup there never leaves your network, so it has nothing to fail open or closed on. An IP list in Cloudflare or AWS WAF answers at your edge too, within the list sizes that post measures.

A paid plan's key, and a wrong one

A paid plan's key answers every field, the proxy flags among them. Create one in the console, where a free account can try every field, and give it to the shared client:

js
const client = new VPNDetection({ apiKey: process.env.VPNDETECTION_API_KEY });

A wrong key looks like an outage, and lasts longer: the page and signup kept working with no address checked, the payout answered 503, and the log read:

console
vpn check failed for 45.134.140.130: unauthorized: invalid API key

That is what failing open does to a mistake of yours: it hides it until someone reads the log.

A key that has used its lookups with every field does the same. Past them, a free plan's key for the rest of the UTC day, and a paid plan's once its month's lookups and any overage you allow are used, each answer carries the basics and no VPN flag. Since vpndetection 6.0.0 that answer raises quota_exceeded, and the middleware treats the lookup as failed. Against a stand-in for our API answering as it does past the cap, the three routes answered as they did for the wrong key, and the log line read quota_exceeded: the organization's lookups with every field are used, beside a warning from the middleware itself.

unauthorized or forbidden is your key: alert someone, since nothing fixes it but a person. quota_exceeded is your allowance: alert on it too, since every route runs unchecked until it renews or you raise it. Pricing lists what each plan adds.

The middleware for each framework is in the docs, starting from our Express tutorial, and the API page shows what a lookup returns.

Written by

  • Uman Shahzad

    Founder & CEO

    Uman has worked on IP data for over eight years, including as lead engineer at IPinfo. He built systems and practices that IP data companies now use to run at scale and keep their data accurate.

Get new posts by email

Or follow along in a feed reader.

RSS feed

Try it on your own traffic.

The detection these posts describe is one API call away, with SDKs for every major language.

00 · Try it

Free lookups, no sign-up.

Paste it into a terminal. Any address answers its VPN, Tor, relay and anycast flags, where it is, which network announces it and its hostname.

curl "https://api.vpndetection.io/146.70.116.130"
{
"ip": "146.70.116.130",
"is_bogon": false,
"is_vpn": true,
"is_relay": false,
"is_tor": false,
"is_anycast": false,
"relay": {},
"tor": {},
"location": {
"continent": "EU",
"continent_name": "Europe",
"country": "AT",
"country_name": "Austria",
"timezone": "Europe/Vienna",
"currency_code": "EUR",
"currency_name": "Euro",
"currency_symbol": "€",
"flag_emoji": "🇦🇹",
"flag_unicode": "U+1F1E6 U+1F1F9"
},
"asn": {
"asn": 9009,
"name": "M247 Europe SRL",
"domain": "m247global.com",
"prefix": "146.70.116.0/24",
"country": "RO",
"rpki_status": "not_found"
},
"hostname": ""
}
01 · Sign up

Try every field, free.

A daily allowance of every field, the evidence behind each flag included.
Past it, lookups answer the basics, with no cap.
No card and no sales call: the key is issued on signup.
The Data plan answers every field on every lookup.