An Oracle client gives up before it reaches the database listener
Fix it fast
Most common cause, 1 of 3A firewall or cloud security rule drops traffic to the listener port
Allow inbound TCP on the listener port (1521 unless your DBA changed it) from the application server's address, on the database host's firewall and in any cloud rule in front of it.
# on a database host that uses firewalld (example)
sudo firewall-cmd --permanent --add-port=1521/tcp
sudo firewall-cmd --reloadShort answer
ORA-12170: TNS:Connect timeout occurred (newer clients: Cannot connect. TCP connect timeout of ...) means the Oracle client could not finish connecting to the database host and port in the allowed time. Oracle names a firewall that drops the traffic, no network path between client and server, and slow networks as the causes. Test the port from the app host first.
Which cause do you have?
From the machine or container where PHP, Python or Java runs, try the database port directly. A probe that hangs and then fails points to cause 1. A host that does not resolve, or resolves to an address you did not expect, points to cause 2. A probe that connects at once while the application still times out points to cause 3.
getent hosts db.example.com
nc -vz -w 10 db.example.com 1521Then find the line you see in this list and open its fix:
- 1A firewall or cloud security rule drops traffic to the listener port
nc waits for the full -w time and then reports a timeout, never Connection refused - 2The host in the connect string is not reachable from where the app runs
The host_port in the message is a private address, localhost inside a container, or a name that resolves differently on the app server - 3The network is slow and the client's connect timeout is short
The port probe connects, but the message names an Outbound connect timeout or a very small TCP timeout value
What does the error look like?
ORA-12170: TNS:Connect timeout occurredORA-12170: Cannot connect. TCP connect timeout of time_interval for host_port or key. (CONNECTION_ID=ID_string).ORA-12170: Cannot connect. Outbound connect timeout of time_interval for host_port or key.
Cause 1 of 3
A firewall or cloud security rule drops traffic to the listener port
You seenc waits for the full -w time and then reports a timeout, never Connection refused
Check
ORA-12170 with a TCP connect timeout is what a silently dropped packet looks like: the client sends its request to port 1521 and no answer ever comes. Oracle's error help lists a firewall that does not allow the connection as a cause, next to delays and missing connectivity. Host firewalls, cloud security groups and network ACLs on either side all count.
nc -vz -w 10 db.example.com 1521Fix
Allow inbound TCP on the listener port (1521 unless your DBA changed it) from the application server's address, on the database host's firewall and in any cloud rule in front of it. Then repeat the probe from the app host.
# on a database host that uses firewalld (example)
sudo firewall-cmd --permanent --add-port=1521/tcp
sudo firewall-cmd --reloadVerify
nc prints that the connection to port 1521 succeeded, and the application connects without ORA-12170.
nc -vz -w 10 db.example.com 1521Confirmed by docs.oracle.com
Cause 2 of 3
The host in the connect string is not reachable from where the app runs
You seeThe host_port in the message is a private address, localhost inside a container, or a name that resolves differently on the app server
Check
The newer ORA-12170 text prints the host and port the client tried, so read it first. A private IP used from outside its network, a VPN that is down, or DB_HOST=localhost inside a Docker container all leave no network path between client and server, which Oracle lists as a cause.
grep -E "^DB_(HOST|PORT|SERVICE_NAME|TNS)=" .envFix
Point the connection at an address the app host can route to. With yajra/laravel-oci8, the oracle connection reads DB_HOST, DB_PORT and DB_SERVICE_NAME (or DB_TNS) from .env, so correct those values and clear the cached config.
# .env
DB_HOST=db.internal.example.com
DB_PORT=1521
DB_SERVICE_NAME=ORCLPDB1
# then
php artisan config:clearVerify
The host_port in any new error matches the address you set, and a test query from the app succeeds.
php artisan tinker --execute="DB::connection('oracle')->select('select 1 from dual');"Confirmed by raw.githubusercontent.com
Cause 3 of 3
The network is slow and the client's connect timeout is short
You seeThe port probe connects, but the message names an Outbound connect timeout or a very small TCP timeout value
Check
When the path exists but the handshake takes longer than allowed, ORA-12170 reports the timeout type and value it hit. TCP.CONNECT_TIMEOUT defaults to 60 seconds; SQLNET.OUTBOUND_CONNECT_TIMEOUT has no default and also covers reaching the instance, and a CONNECT_TIMEOUT in the connect string overrides it. Someone may have set one of them very low.
grep -iE "CONNECT_TIMEOUT|RECV_TIMEOUT" "$TNS_ADMIN/sqlnet.ora" /opt/oracle/instantclient_*/network/admin/sqlnet.ora 2>/dev/nullFix
Raise the value in the client's sqlnet.ora. With Instant Client that file lives in the network/admin folder of the Instant Client directory, or wherever TNS_ADMIN points. Keep it bounded so a real outage still fails fast.
# <Instant Client directory>/network/admin/sqlnet.ora, or $TNS_ADMIN/sqlnet.ora
TCP.CONNECT_TIMEOUT=20 sec
SQLNET.OUTBOUND_CONNECT_TIMEOUT=30 secVerify
Connections succeed on the slow path, and a deliberately wrong host still fails after the new limit rather than hanging.
php artisan tinker --execute="DB::connection('oracle')->select('select 1 from dual');"Confirmed by docs.oracle.com
How do I stop it coming back?
- Add a start-up check that opens one database connection with a short timeout, so a closed port fails the deploy instead of the first request.
- Keep the database address in one place (.env or tnsnames.ora) and record which firewall rule allows each app server to reach it.
- Set TCP.CONNECT_TIMEOUT and SQLNET.OUTBOUND_CONNECT_TIMEOUT on purpose in the client sqlnet.ora rather than leaving the 60-second TCP default in place.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Spotless Laundry, EZ Estimater.