# The Network Adapter could not establish the connection

**URL:** <https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885>\
**Category:** Logstash\
**Tags:** jdbc\
**Created:** [March 16, 2022, 5:31pm UTC](https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885 "2022-03-16T17:31:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipeneto04](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@felipeneto04](https://discuss.elastic.co/u/felipeneto04)\
**Post date:** [March 16, 2022, 5:31pm UTC](https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885/1 "2022-03-16T17:31:55Z")

</div>

I'm new here and also to logstash.  
I'm having trouble trying to connect.  
I have several branches spread across Brazil, I get data from each one through a VPN connection, and I use a .sh scheduled in CRON to call the scripts, but when the access to one of the branches freezes I can't finish that call and go to the next.  
I want you to try 3 times and after the third try it's finished.

Conf:

```auto
input { jdbc { jdbc_driver_library => "/etc/logstash/ojdbc8.jar" 
	      jdbc_driver_class => "Java::oracle.jdbc.driver.OracleDriver" 
              jdbc_connection_string => "jdbc:oracle:thin:@//x.x.x.x:1521/XE" 
	      jdbc_user => "user" 
	      jdbc_password => "password"
	connection_retry_attempts => 3
	connection_retry_attempts_wait_time => 300
    statement_filepath => "/etc/logstash/sql/franquia/xtransacao_franquia_toff.sql"
  }
}
output { elasticsearch { hosts => ["http://localhost:9200"] index => "index"
    user => "elastic" password => "password"
  }
}

```

Result01:

```auto
[2022-03-16T00:04:20,694][ERROR][logstash.inputs.jdbc][main][e96d8a80a28becfb9fc7e8f415363a3a2cd75d922e53fadbc0f6c034deb089bc] 
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
	at oracle.jdbc.driver.T4CConnection.logon(oracle/jdbc/driver/T4CConnection.java:805) ~[ojdbc8.jar:18.15.0.0.0]
	at oracle.jdbc.driver.PhysicalConnection.connect(oracle/jdbc/driver/PhysicalConnection.java:782) ~[ojdbc8.jar:18.15.0.0.0]
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(oracle/jdbc/driver/T4CDriverExtension.java:39) ~[ojdbc8.jar:18.15.0.0.0]
	at oracle.jdbc.driver.OracleDriver.connect(oracle/jdbc/driver/OracleDriver.java:704) ~[ojdbc8.jar:18.15.0.0.0]
...
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
...
Caused by: java.io.IOException: Connection timed out, socket connect lapse 31582 ms.
...
Caused by: java.net.ConnectException: Connection timed out

```

Enters an infinite loop causing the queue to stop.

---

<div class="post-metadata">

**Author:** ![felipeneto04](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@felipeneto04](https://discuss.elastic.co/u/felipeneto04)\
**Post date:** [March 16, 2022, 5:35pm UTC](https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885/2 "2022-03-16T17:35:49Z")

</div>

I already have several extractions running, my problem is just ending the script when I can't access the destination:  
If the first one doesn't finish it doesn't go to the second.  
Here's an example .sh:

```auto
#!/bin/bash

DATAHORA1=$(datahora)
curl -X DELETE -u elastic:xxxxxx "localhost:9200/cs_rz_pending" > /etc/logstash/log_execucao/cs_rz_pending/cur_DEL_cs_rz_pending_"$DATAHORA1".log
/usr/share/logstash/bin/logstash -f /etc/logstash/config/sap/cs_rz_pending.conf --path.data /home/lbelk/temp1 --path.settings /etc/logstash > /etc/logstash/log_execucao/cs_rz_pending/lgtsh_cs_rz_pending_"$DATAHORA1".log

DATAHORA2=$(datahora)
curl -X DELETE -u elastic:xxxxxx "localhost:9200/cs_dif_101j1" > /etc/logstash/log_execucao/cs_dif_101j1/cur_DEL_cs_dif_101j1_"$DATAHORA2".log
/usr/share/logstash/bin/logstash -f /etc/logstash/config/sap/cs_dif_101j1.conf --path.data /home/lbelk/temp1 --path.settings /etc/logstash > /etc/logstash/log_execucao/cs_dif_101j1/lgtsh_cs_dif_101j1_"$DATAHORA2".log

DATAHORA3=$(datahora)
curl -X DELETE -u elastic:xxxxxx "localhost:9200/cs_dif_z101" > /etc/logstash/log_execucao/cs_dif_z101/cur_DEL_cs_dif_z101_"$DATAHORA3".log
/usr/share/logstash/bin/logstash -f /etc/logstash/config/sap/cs_dif_z101.conf --path.data /home/lbelk/temp1 --path.settings /etc/logstash > /etc/logstash/log_execucao/cs_dif_z101/lgtsh_cs_dif_z101_"$DATAHORA3".log

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 16, 2022, 6:20pm UTC](https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885/3 "2022-03-16T18:20:47Z")

</div>

SQLRecoverableException is a sub-class of java.sql.SQLException, so I would expect the code to be going through [this](https://github.com/logstash-plugins/logstash-integration-jdbc/blob/6a75566cad54805ff05a50a8a4879aede54a7967/lib/logstash/plugin_mixins/jdbc/jdbc.rb#L126) path. Are you seeing the "Unable to connect to database" messages?

---

<div class="post-metadata">

**Author:** ![felipeneto04](https://avatars.discourse-cdn.com/v4/letter/f/838e76/32.png) [@felipeneto04](https://discuss.elastic.co/u/felipeneto04)\
**Post date:** [March 16, 2022, 7:04pm UTC](https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885/4 "2022-03-16T19:04:10Z")

</div>

Yes, in the log there is also this message:

`[2022-03-16T00:04:20,706][ERROR][logstash.inputs.jdbc][main][e96d8a80a28becfb9fc7e8f415363a3a2cd75d922e53fadbc0f6c034deb089bc] **Unable to connect to database**. Tried 1 times {:message=>"Java::JavaSql::SQLRecoverableException: IO Error: The Network Adapter could not establish the connection", :exception=>Sequel::DatabaseConnectionError, :cause=>java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection, :backtrace=>["oracle.jdbc.driver.T4CConnection.logon(oracle/jdbc/driver/T4CConnection.java:805)", "oracle.jdbc.driver.PhysicalConnection.connect(oracle/jdbc/driver/PhysicalConnection.java:782)", "oracle.jdbc.driver.T4CDriverExtension.getConnection(oracle/jdbc/driver/T4CDriverExtension.java:39)", "oracle.jdbc.driver.OracleDriver.connect(oracle/jdbc/driver/OracleDriver.java:704)", "jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(jdk/internal/reflect/NativeMethodAccessorImpl.java:62)", "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(jdk/internal/reflect/DelegatingMethodAccessorImpl.java:43)", "java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:566)", ...`

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 16, 2022, 10:58pm UTC](https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885/5 "2022-03-16T22:58:36Z")

</div>

OK, so the retry logic is working as expected. You would like logstash to exit if it fails to start the pipeline. Instead I suspect it will endlessly try to restart the pipeline. There is no way to turn that off.

Instead of using a jdbc input it might be possible to fetch the data to a file using an SQL tool, then cat the file into logstash with a stdin input. That will shutdown the instance after it reaches end-of-file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 13, 2022, 10:58pm UTC](https://discuss.elastic.co/t/the-network-adapter-could-not-establish-the-connection/299885/6 "2022-04-13T22:58:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
