Skip to content

ORA-12170: TNS Connect Timeout — Firewall, Host or Port?

ORA-12170 means your connection attempt got silence, not a refusal. How to prove whether a firewall, a security list, a wrong IP or a slow handshake ate it, and why raising the timeout only makes it fail slower.

ora-12170 ora-12535 connect-timeout firewall sqlnet-ora oracle-net oracle-database
Gopi Gorantala
Reading Progress

On This Page

134,675 milliseconds.

That's how long a plain Java socket sat there in my lab before giving up on a port behind a firewall rule that drops packets. No error for two and a quarter minutes, then a timeout. Put an Oracle client in front of the same rule and you get ORA-12170, after whatever timeout your stack happens to have, which is rarely the one you think.

ORA-12170 tells you the least of any Oracle Net error, because nothing told the client anything. Oddly, that makes it quick to triage.

The silence, in three dialects

From a 19c client (SQL*Plus, SQL Developer in OCI mode, anything on Instant Client 19), the whole message is one line:

ERROR:
ORA-12170: TNS:Connect timeout occurred

From a 23ai/26ai client, Oracle rewrote it to say which timeout fired, for which address. This is the format from Oracle's error help page for ORA-12170 and the 23ai Net Services troubleshooting entry, quoted from the docs, not my lab:

ORA-12170: Cannot connect. TCP connect timeout of 30s for host 10.9.7.5 port 1522. (CONNECTION_ID=1ABcDEabCd1aB+AbCdE1aB==)

The first words after "Cannot connect." are the useful part. TCP connect timeout, Outbound connect timeout and Receive timeout are three different failures, and I'll come back to why.

Then there's the cousin, ORA-12535: TNS:operation timed out. Same family. On a client it usually rides along under 12170. On the database server it shows up in the alert log, as a block like this one (19.18, quoted from an Oracle Forums post, trimmed):

Fatal NI connect error 12170.
  VERSION INFORMATION:
        TNS for Linux: Version 19.0.0.0.0 - Production
        Version 19.18.0.0.0
  Time: 24-DEC-2024 17:03:02
    ns main err code: 12535
TNS-12535: TNS:operation timed out
    ns secondary err code: 12609
    nt main err code: 0
    nt secondary err code: 0
    nt OS err code: 0
  Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=xx.xx.xx.xx)(PORT=32458))

That one is the server complaining about a client, a different problem wearing the same number. It gets its own section further down.

What narrows it fastest is when it fails: at connect time, after a pause matching a round number (20, 30, 60 seconds). That's a dropped connection.

Did anything come back at all?

My first instinct the first time I chased one of these was the listener. Restart it, check lsnrctl status, look for the service. It seemed reasonable, because every other connection error I'd had that month was a listener problem. It was a waste of twenty minutes. A listener can't time you out if your packets never reach its host.

So the first question is about the network, and you answer it from the application's host, not your laptop and not the database server:

time nc -vz -w 5 db-fxrates.internal 1521        # run this from the pod, VM or CI runner that fails

Three outcomes, three different articles:

What nc does What it means Oracle code you'll see
"Connection refused", in milliseconds Something answered "no": no listener, or a firewall that rejects ORA-12541
Hangs, then "timed out" after 5 s Nobody answered at all: packets dropped somewhere ORA-12170, this article
"succeeded" TCP is fine; the timeout is later, in the Oracle handshake ORA-12170 with Outbound or Receive, or ORA-12514

No nc in the container image? bash -c 'cat < /dev/null > /dev/tcp/db-fxrates.internal/1521' does the same probe with nothing installed, and on Windows it's Test-NetConnection db-fxrates.internal -Port 1521.

If nc succeeds and your app still times out, read the 23ai message again (or the trace, below). And if you're still unsure which of the connection errors you even have, the three-way comparison sorts them by how far the connection got.

A firewall in one iptables line

I didn't have a Docker daemon or a way to pull an Oracle image in this session, so I built the part of the lab that explains the mechanism without Oracle, and ran it. ORA-12170 is what an Oracle client says when the socket underneath it times out, so a socket is enough to watch it happen. The Oracle half is at the end, as commands I didn't run.

What I ran it on: Ubuntu 24.04.5, kernel 6.18, OpenJDK 21.0.13, OpenBSD netcat 1.226, iptables as root inside a throwaway container. net.ipv4.tcp_syn_retries was the Linux default, 6.

Don't run the iptables lines on a machine you care about. Run them in a disposable container or VM.

The probe. Any thin driver (JDBC thin, python-oracledb thin) starts with exactly this: open a TCP socket, then wait for the listener to talk.

import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Probe {
    public static void main(String[] args) {
        String host = args[0];
        int port = Integer.parseInt(args[1]);
        int connectMs = Integer.parseInt(args[2]);   // 0 = no limit, the OS decides
        int readMs = args.length > 3 ? Integer.parseInt(args[3]) : 0;
        long start = System.nanoTime();
        try (Socket s = new Socket()) {
            s.connect(new InetSocketAddress(host, port), connectMs); // the TCP handshake
            long ms = (System.nanoTime() - start) / 1_000_000;
            System.out.println("TCP connected after " + ms + " ms");
            if (readMs > 0) {
                s.setSoTimeout(readMs);                            // wait for the server to say anything
                InputStream in = s.getInputStream();
                in.read();
            }
        } catch (Exception e) {
            long ms = (System.nanoTime() - start) / 1_000_000;
            System.out.println(e.getClass().getName() + ": " + e.getMessage() + " after " + ms + " ms");
        }
    }
}

Step 1: a stand-in listener. nc -lk 0.0.0.0 1521 &, then java Probe.java 127.0.0.1 1521 5000:

TCP connected after 90 ms

Step 2: a firewall that rejects.

iptables -A INPUT -p tcp --dport 1521 -j REJECT --reject-with tcp-reset
java Probe.java 127.0.0.1 1521 5000
java.net.ConnectException: Connection refused (connect failed) after 7 ms

Seven milliseconds. The listener is running and you'd still get ORA-12541 here, because a reject looks exactly like "nobody home".

Step 3: a firewall that drops. This is the one.

iptables -F INPUT
iptables -A INPUT -p tcp --dport 1521 -j DROP
java Probe.java 127.0.0.1 1521 5000      # 5 s connect timeout
java Probe.java 127.0.0.1 1521 0         # no timeout: let the kernel decide
java.net.SocketTimeoutException: Connect timed out after 5010 ms
java.net.ConnectException: Connection timed out after 134675 ms

Same rule, same port. With a timeout you get it back in five seconds. Without one, the kernel retransmits the SYN six times with exponential backoff and gives up after about two minutes, plus JVM startup. That second line is the raw material of ORA-12170.

Step 4: TCP works, the server never speaks. A "listener" that accepts connections and then says nothing, on port 1600:

python3 -c "
import socket
s = socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('0.0.0.0', 1600)); s.listen(5); conns = []
while True:
    c, _ = s.accept(); conns.append(c)
" &
java Probe.java 127.0.0.1 1600 5000 5000
TCP connected after 6 ms
java.net.SocketTimeoutException: Read timed out after 5015 ms

That's the Receive timeout flavour: the handshake completed, then silence. In real life it's an overloaded listener, a stuck server, or a middlebox that lets the SYN through and eats what comes after.

Forcing levers. The 5-second timeouts are lab numbers. Oracle Net's own default TCP connect timeout is 60 seconds; python-oracledb's is 20. The DROP rule stands in for a cloud security list, a security group or a corporate firewall.

Teardown. iptables -F INPUT, then kill the background nc and Python processes. Forget the flush and the next lab you run in that container fails in a very confusing way.

The Oracle version (not run here). With Docker, pin your own image tag, publish the port, and put the drop in front of it:

docker run -d --name lab-oracle -p 1521:1521 -e ORACLE_PASSWORD=LabOnly_2026 gvenzl/oracle-free:23-slim-faststart
# wait for DATABASE IS READY TO USE! in docker logs, then on a disposable Linux VM:
sudo iptables -I DOCKER-USER -p tcp --dport 1521 -j DROP
sqlplus -L system/LabOnly_2026@'//vm-ip:1521/FREEPDB1?transport_connect_timeout=5'

Expect ORA-12170 after about five seconds, in your client's wording. ORA-12541 instead means your rule rejects rather than drops. Clean up with sudo iptables -D DOCKER-USER -p tcp --dport 1521 -j DROP and docker rm -f lab-oracle.

Short version

Your client sent a connection request and heard nothing back before its timer ran out. Almost always that's a firewall or routing rule dropping packets, or an address that leads nowhere. Rarely, the network's fine and the server is too slow to answer.

What the client is actually waiting for

An Oracle connection is a stack of waits, and each one has its own timer.

First, TCP. Your client sends a SYN and waits for a SYN-ACK. A reject comes back as a reset, instantly. A drop comes back as nothing, so the client's kernel retries, waiting longer each time. The Oracle-level limit on this stage is TCP.CONNECT_TIMEOUT in the client sqlnet.ora, or TRANSPORT_CONNECT_TIMEOUT in the connect descriptor, which wins if both are set. The 19c Net Services Reference puts Oracle Net's default TCP connect timeout at 60 seconds.

Then the Oracle Net handshake. TCP is up, and now the client sends its connect packet and waits for the listener to accept, maybe redirect it, and hand it to a server process. The limit on the whole thing, TCP included, is SQLNET.OUTBOUND_CONNECT_TIMEOUT in sqlnet.ora or CONNECT_TIMEOUT in the descriptor. In the 19c sqlnet.ora reference its default is "None", and the doc says outright that without it a connect to an unreachable host can block for the 60-second TCP default.

And then receives, bounded by SQLNET.RECV_TIMEOUT, which has nothing set by default either.

The 23ai/26ai message names which of these fired, honestly the best change Oracle has made to this error in years. TCP connect timeout means the SYN never got an answer, so it's the network. Outbound connect timeout or Receive timeout means you reached something that didn't finish the conversation. On a 19c client you work that out yourself, with nc.

Here's the surprise from the lab, and the reason I now set connect timeouts explicitly everywhere. The same dropped packet stalls each client for a different amount of time:

Client Default connect wait on a dropped SYN Where that comes from
Plain Java socket, no timeout ~127 s on Linux (134.7 s in my lab, with JVM startup) kernel: tcp_syn_retries = 6
Oracle Net (OCI, SQL*Plus, Instant Client) 60 s the documented default TCP connect timeout
JDBC thin, oracle.net.CONNECT_TIMEOUT default 0 in the ojdbc 23.7 javadoc, so it falls to the descriptor or the OS OracleConnection javadoc
python-oracledb, tcp_connect_timeout 20 s (60 s before 2.3.0) ConnectParams docs

So the Python loader fails in 20 seconds, SQL*Plus on the jump box takes a minute, and a Java service with no timeout hangs for two, holding a pool thread the whole time. Same outage, different stories in different logs.

The drop-versus-reject split explains one more thing. Cloud filters like AWS security groups drop what they don't allow, while host firewalls like firewalld default to rejecting. So the same closed port gives ORA-12170 in one environment and ORA-12541 in another.

Proving which hop eats the SYN

You've confirmed the drop with nc. Now find where. Packet captures settle this faster than any amount of config reading, if you can get them. They usually need root, so ask whoever owns the host.

On the client:

sudo tcpdump -ni any 'tcp port 1521 and host 10.20.4.17'

You'll see the SYN go out, then the same SYN again a second later, then two seconds later, then four. Nothing comes back. That's the client side proven.

On the database host, at the same time:

sudo tcpdump -ni any 'tcp port 1521 and host <client-ip>'

Now it forks:

  • No SYN arrives. Something between the two hosts drops it: a security list or NSG on the database subnet, a security group, an on-prem firewall, a missing VPN route, a Kubernetes egress NetworkPolicy on the client side. Fix the rule, and fix it for the narrowest source range that works.
  • SYN arrives, SYN-ACK leaves, the client never sees it. The return path is broken: asymmetric routing, a NAT gateway, a stateful firewall that only knows one direction. This is the one that makes people swear the firewall is open, because the inbound rule really is.
  • Full handshake, then the client times out anyway. You're in Outbound/Receive territory. Look at the listener log on that host for your connection, and check whether the listener is redirecting you somewhere unreachable (next bullet).

There's a RAC-specific version of that last case. Your client reaches the SCAN listener fine, the SCAN listener redirects it to a node VIP, and that VIP is on a range your firewall doesn't allow. The first hop works, the second times out, and every nc test you ran against the SCAN name says the port is open. lsnrctl services on the SCAN shows where it's sending people (reading lsnrctl output has the details).

Can't get packet captures? A client-side Oracle Net trace shows the same thing from inside the driver. In the client sqlnet.ora (and remove it afterwards, traces grow fast):

TRACE_LEVEL_CLIENT = 16
TRACE_DIRECTORY_CLIENT = /tmp/oranet-trace
DIAG_ADR_ENABLED = OFF

On a 23ai client, the CONNECTION_ID from the error finds the right trace file among many.

Before the firewall ticket, check the boring stuff. A private address used from outside the VCN, a stale DNS entry after a migration, or an IPv6 address on a network that doesn't route IPv6 all lead to an address nobody owns, which gives a drop, not a refusal.

The fixes, and what each one costs

Cause Fix Cost
Rule drops the port Allow the client's CIDR to the listener port (1521, or 1522 for TLS) A change ticket; keep the source range narrow
Wrong address Fix the host in the descriptor, DNS, or /etc/hosts Find every config that had the old one
Broken return path Fix routing or NAT so replies go back the same way Network team time; hard to prove without captures
SCAN redirect to blocked VIPs Open the node VIP range too More rules than people expect
Server too slow to answer (Outbound/Receive) Find out why the listener or instance is slow; raise the timeout only for honestly slow links Raising it hides the next real outage

And the two non-fixes that keep circulating, including in Oracle's own action text. Disabling the firewall proves the theory and then has to be undone; do it on a lab VM, not a production network. Raising the timeout on a dropped SYN changes nothing except how long you wait before the same failure. A packet that's being dropped at 30 seconds is still being dropped at 300.

When the alert log is the one complaining

The server-side TNS-12535 block in the alert log is the database's view of a client that went quiet. With nt secondary err code: 110 on Linux (errno 110 is ETIMEDOUT), the server's socket timed out talking to the client, often because a firewall silently dropped an idle connection and the next packet went nowhere. With a ns secondary err code of 12609 (TNS:Receive timeout occurred), the server hit its own receive or inbound-connect limit.

The client sees a closed connection for the same event, not ORA-12170, and the fix is on the pool side: EXPIRE_TIME probes (descriptor, 19c clients and later, or SQLNET.EXPIRE_TIME on the server) and pool lifetimes shorter than the firewall's idle cutoff. That story lives in connection pools that survive restarts and firewalls. Don't set SQLNET.INBOUND_CONNECT_TIMEOUT to 0 to make the alert log quiet: it's 60 seconds by default for a reason, and 0 removes the protection against clients that connect and never authenticate.

Timeouts you choose on purpose

This bites once and teaches the right habit: never let a default decide how long your app waits for a database.

One descriptor per environment, with the timeouts written down where the next person can see them:

FXRATES =
  (DESCRIPTION =
    (CONNECT_TIMEOUT = 15)(TRANSPORT_CONNECT_TIMEOUT = 3)
    (RETRY_COUNT = 3)(RETRY_DELAY = 2)
    (EXPIRE_TIME = 5)
    (ADDRESS_LIST =
      (LOAD_BALANCE = ON)
      (ADDRESS = (PROTOCOL = TCP)(HOST = db-fxrates-scan.internal)(PORT = 1521)))
    (CONNECT_DATA = (SERVICE_NAME = fxrates_app.internal)))

TRANSPORT_CONNECT_TIMEOUT short (3 seconds is generous inside one region), so a dropped address fails fast and the client moves to the next one. CONNECT_TIMEOUT longer, because it covers the whole handshake including redirects. RETRY_COUNT and RETRY_DELAY ride out a switchover instead of failing the first attempt. This is the shape Oracle's own high availability guidance on TNS string parameters recommends, with CONNECT_TIMEOUT larger than TRANSPORT_CONNECT_TIMEOUT.

The same settings in the places you'll actually put them:

# JDBC URL, using the full descriptor (works with ojdbc8/11 thin)
spring.datasource.url=jdbc:oracle:thin:@(DESCRIPTION=(CONNECT_TIMEOUT=15)(TRANSPORT_CONNECT_TIMEOUT=3)(RETRY_COUNT=3)(RETRY_DELAY=2)(ADDRESS=(PROTOCOL=TCP)(HOST=db-fxrates-scan.internal)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=fxrates_app.internal)))
import oracledb

conn = oracledb.connect(
    user="fx_loader", password=pw,
    dsn="db-fxrates-scan.internal:1521/fxrates_app.internal",
    tcp_connect_timeout=3,      # seconds; default is 20
    retry_count=3, retry_delay=2,
)

If you use EZConnect, the 19c-and-later syntax accepts the same parameters after a question mark, like //db-fxrates-scan.internal:1521/fxrates_app.internal?connect_timeout=15&transport_connect_timeout=3. Whether your service name is right is a separate question; SID vs service name covers that.

The check that runs before the deploy does

Most ORA-12170s I've seen were born in a network change nobody connected to the database: a new subnet, a new cluster, a security list rewritten by Terraform. So the cheapest prevention is a TCP check from where the app actually runs, before the app does:

initContainers:
  - name: db-reachable
    image: busybox:1.36
    command: ["sh", "-c", "nc -z -w 3 db-fxrates-scan.internal 1521 || { echo 'port 1521 unreachable (dropped or refused)'; exit 1; }"]

A pod that can't reach the database never starts, and the event says why in one line instead of a two-minute hang in the app log. Do the same as the first step of a CI job that talks to a shared database.

In monitoring, alert on connection acquisition time, not only on errors. A jump from 5 ms to 3,000 ms on new connections is a dropped address in a list somewhere, and it shows up before the failover that turns it into ORA-12170. On the server, count TNS-12535 blocks in the alert log per hour; a sudden rise means a firewall started cutting idle sessions.

Version notes worth checking on every upgrade:

  • 19c clients print ORA-12170: TNS:Connect timeout occurred; 23ai/26ai clients print Cannot connect. with the timeout type, value, host and port, plus a CONNECTION_ID. Log parsers that match the old string will miss the new one.
  • python-oracledb dropped its default tcp_connect_timeout from 60 to 20 seconds in 2.3.0, and its default retry_delay went from 0 to 1 second.
  • In the ojdbc 23.7 javadoc, oracle.net.CONNECT_TIMEOUT and oracle.net.OUTBOUND_CONNECT_TIMEOUT both default to 0. If your descriptor sets nothing, the OS decides. Check this on your driver version rather than trusting mine.

Getting to the bottom of this took me more than a day, mostly because three Oracle docs each describe a different slice of the timeout stack. It's written down here so you don't spend that day, on any version.

Screenshot this bit

  • Time the failure. Instant means refused, a pause that matches a timeout means dropped.
  • Run nc -vz -w 5 host 1521 from the app's host, never from your laptop.
  • On a 23ai/26ai client, the words after "Cannot connect." tell you which stage failed. TCP connect is the network every time.
  • Raising a timeout never fixes a dropped packet. Set short, explicit timeouts and fix the rule.
  • TNS-12535 in the alert log is the server's complaint about clients, usually idle connections cut by a firewall.

ORA-12170, the way people search it

How do I fix ORA-12170 TNS connect timeout occurred?

Find out whether packets reach the database host at all. Run nc -vz -w 5 <host> 1521 from the machine that fails; if it hangs, a firewall, security list or route is dropping traffic, or the address is wrong. Fix that rule or address. Only when TCP connects and the Oracle handshake is slow should you look at timeouts or at the listener.

Is ORA-12170 a firewall problem?

Usually. A firewall or cloud security rule that drops traffic gives ORA-12170, while one that rejects it gives ORA-12541. The other common causes are an unreachable address (a private IP from outside its network, stale DNS) and a broken return path. On a 23ai/26ai client, "TCP connect timeout" in the message confirms it's the network.

What is the difference between ORA-12170 and ORA-12535?

ORA-12170 is the client saying the connect timed out. ORA-12535, "TNS:operation timed out", is the generic Oracle Net timeout underneath it, and it's the code that appears as TNS-12535 in the database alert log when the server times out talking to a client. Same family, but the alert log version usually points at idle connections cut by a firewall rather than failed logins.

Should I increase SQLNET.OUTBOUND_CONNECT_TIMEOUT to fix ORA-12170?

Not when the connection is being dropped; a dropped packet stays dropped no matter how long you wait. Raise it only if TCP connects fine and the handshake is legitimately slow, such as across a long-distance link. In most apps you want shorter connect timeouts, set explicitly with TRANSPORT_CONNECT_TIMEOUT and CONNECT_TIMEOUT, so failures surface in seconds.

ora-12170ora-12535connect-timeoutfirewallsqlnet-oraoracle-netoracle-database

Staff engineer architecting Kafka and Flink platforms for banking, where a dropped event is a reconciliation break, not a retry. Through javahandbook.com, I share production-tested guidance on building reliable event-driven systems.

Comments