why JBoss would destroy connection pool on an error? - java

I have a web application running on JBoss 4.2.3 connecting to a SQL Server 2008 R2 database through JTDS 1.2.2 driver. The Datasource is setup to have minimum 10 connections in the pool. This is the ds file jtds-ds.xml: (I have replaced the real jndi name, server name, database name, user name and password).
<datasources>
<local-tx-datasource>
<jndi-name>MyDS</jndi-name>
<connection-url>jdbc:jtds:sqlserver://MyServer/MyDatabase;tds=8.0;lastupdatecount=true</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<user-name>MyUserName</user-name>
<password>MyPassword</password>
<set-tx-query-timeout>true</set-tx-query-timeout>
<!--
sql to call on an existing pooled connection when it is obtained from pool
-->
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<!-- Pooling Parameters -->
<prepared-statement-cache-size>500</prepared-statement-cache-size>
<min-pool-size>10</min-pool-size>
<max-pool-size>40000</max-pool-size>
</local-tx-datasource>
</datasources>
I run the SQL Server Profiler. After the JBoss starts in the SQL Server Profiler, I can see 10 database connections to the MyDatabase database from the web application . Whenever any user works on the web application, I can see it in SQL Server Profiler. Everything looks good.
I start a process which is a very long process and insert million of rows in database. The process inserts 1000 rows at a time i.e. it gets connection from pool, insert 1000 rows in database, then close connection. I can see it in SQL Server Profiler and it is working ok.
While the process was running I got a warning in the log file and I think it was because the connection was lost to the database server
2015-03-26 11:50:35,611 WARN [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Unable to fill pool
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Network error IOException: Connection timed out: connect)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:190)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:619)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.fillToMin(InternalManagedConnectionPool.java:534)
at org.jboss.resource.connectionmanager.PoolFiller.run(PoolFiller.java:74)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: Network ` IOException: Connection timed out: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:385)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:172)
... 4 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:304)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:255)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:310)
... 7 more
After this error, the SQL Server Profiler is not showing any connections for the web application. JBoss is still running. Why JBoss would destroy its connection pool in this case?
UPDATE:
When another user's request comes in the web application, I saw the SQL Server Profiler shows me 4 connections by the web application. So it is at least start building the connection pool again although I would expect it to show 10 connections.
My question still is that when such an error occurs (Connection timed out), why JBoss drop the whole 10 connections in the connection pool? The process was using only 1 connection, the other 9 connections were not being used as there was nobody else using the web application when the process was run. Also is it possible for JBoss to rebuild its connection pool by itself when it was somehow destroyed? I thought check-valid-connection-sql tag does that trick?

Related

Wildfly Datasource via VPN to MS SQL Server

currently, I am facing some odd behavior.
I have a Java EE Web Application that I am deploying to a wildfly server. This Java EE Application needs a database to which we need to connect via vpn. We are using OpenVPN. When I am using SSMS I have no problems connecting to the database. When I am using pure JDBC, there also is no problem.
But if I am creating a datasource in wildfly (and I am using the exact same jdbc connection url) it does not working. I am using the wildfly admin ui and click the test-button.
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 10.1.115.51, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
I mean, the stack trace is pretty clear. However, the connection should be possbile as I connect via ssms and pure jdbc. Just wildfly datasource is not working.
Furhtermore, I have installed a MS SQL Server on the same mashine the wildfly is running on and using this MS SQL instance the datasource is working fine.
The jdbc url connection url is the following:
jdbc:sqlserver://< ip >:1433;databaseName=projdat;user= ** ;password= **
I have compared the jdbc url connection urls multiple times. Both in the pure jdbc and in the datasource they are the same.
Does anybody have any ideas? Is possible that I need to configure openvpn in a special way that wildfly can connect or do I need to configure Wildfly to be able to connect via vpn. Or do I have to configure the MS SQL Server in special way?
Version of MS SQL Server: 12
Version Wildfly: 19.0.0.Final
SQL Server driver: mssql-jdbc-8.2.2.jre8.jar
I apreciate any hint or advise.
Apparently, I was using an older version of Wildfly (in fact, it was wildfly 16). After I upgraded to Wildfly 19, it is now working. However, I have no clue why it was not working with wildfly 16.

Caused by: java.net.NoRouteToHostException: Cannot assign requested address (Address not available)

I have java application that connect to mysql on docker. when i run load test to save and update data to mysql, first it run corectly but, after a while i got the
Caused by: java.net.NoRouteToHostException: Cannot assign requested address (Address not available)
and program exit immediately.
my program connect to mysql by hibernate and i used the following code to interact with database:
Session curentSession = sessionFactory.getCurrentSession();
curentTransaction = curentSession.beginTransaction();
curentSession.update(entity);
curentTransaction.commit();
It seem that when hibernate open session with getcurrentSession(), close it after transaction commit, but the tcp connection is still open with status of "TIME_WAIT" so when i run netstat -natp i got the huge number of connection to 3306 (mysql port). so i have two solution:
change the design of my connection to database that not close and reopen connection in each transaction.
change the time of connection wait in status "time_wait" with:
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
In addition i found that change the tcp_fin_timeout is not good solution in my case. i change the dataSource from DriverManagerDataSource to HikariDataSource and used the maximumPoolSize to manage the connection to mysql database.
so the problem of huge connection to mysql database gone away. ;)
good luck

NoHostAvailableException with 1000 concurrent request to Cassandra with DataStax Java Driver

The setup:
-2-node Cassandra 2.0.7.31 cluster
-replicas=1
-With default configuration
-Using DataStax java driver 1.0
Activity
Simple insert query using QueyBuilder class
Result
com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.181.13.239 ([/10.181.13.239] Unexpected exception triggered))
at com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:64)
at com.datastax.driver.core.ResultSetFuture.extractCauseFromExecutionException(ResultSetFuture.java:214)
at com.datastax.driver.core.ResultSetFuture.getUninterruptibly(ResultSetFuture.java:169)
at com.jpmc.es.rtm.storage.impl.EventExtract.main(EventExtract.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.181.13.239 ([/10.181.13.239] Unexpected exception triggered))
at com.datastax.driver.core.RequestHandler.sendRequest(RequestHandler.java:98)
at com.datastax.driver.core.RequestHandler$1.run(RequestHandler.java:165)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
Problem was that at my end I have created one thread one connection model. Which is quite synchronous. But Datstax driver works asynchronously(its using netty for that i guess) and taking multiple request on single connection. so in my case I one session for each request and guess what? I have left with pool of open connection b/w Driver and Cassandra. Server got choked so does the Driver. Problem was solved simply by letting Driver manage its pool.
Datastax java driver by default maintain minimum amount of connection for handling Certain amount of simultaneous Request.
Spec says that driver have a limitation of handling at the most 128 request per connection.so When we driver find that more than 128 request is coming Then it only open connection. So Driver is beautifully managing connection pool.[ http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/PoolingOptions.html] This link was helpful
Go to your cassandra.yaml file. It will be present in the conf folder of your cassandra installation.
For listen_address give the IP address of the cassandra server. eg.
listen_address: 10.181.13.239
and then restart the cassandra server. Also check the port for native transport is not commented. There should be an entry like
native_transport_port: 9042

Connection refused: connect Error in Java + Hibernate

I am trying to do this tutorial and when I got to the hibernate part, I get this errors:
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataS
ource.java:146)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(Wrap
perConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(Wrap
perConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourceP
oolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.ja
va:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAc
quiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.j
ava:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(Basic
ResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolA
synchronousRunner.java:648)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.jav
a:288)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331)
... 10 more
Here is the hibernate.cfg.xml part of accessing the database:
<!--Database connection settings-->
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;databaseName=MyTut1db</property>
<property name="connection.username">sop1</property>
<property name="connection.password">myPW1</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
The user sop1 was created in MS SQL Server 2012 Express edition as:
CREATE LOGIN sop1
WITH PASSWORD = 'myPW1';
USE MyTut1db;
GO
CREATE USER sop1 FOR LOGIN sop1;
GO
The database properties are in the figure below:
I have inabled the TCP-IP from MS SQL Server Configuration Manager (TCP Port is 1433), but the problem still persists.
I have also closed the antivirus for a while.
I am asking for some help: What else can it be? How do I verify the user? How do I know that localhost:1433 is the right server?
I would check things following these steps:
Ensure that SQL Server is up and running. Check your running services to see if SQL Server service is up.
I would check the SQL Server Configuration Manager to see if the TCP/IP communication is enabled.
I would check my firewall settings. Perhaps something is in the way between SQL Server and the client.
I would check if another application from the same client can connect to the same server. Then I would check the connection string differences.
If all of the above were playing correctly, then I would check the privileges on the specific SQL Server, on the specific database, for the account I am trying to connect with. Allow everyone to use this database as a first step to check if it is an account-permissions problem.
Hope I helped!
localhost will always be the server your Java is running on - it's saying "Talk back to the same machine".
If your database is hosted on a different server, you need to put that server name in the configuration.
Please the check the following
Click Start >Programs -> Microsoft Sql Server 2008 R2 -> Configuration Tools -> Sql Server Configuration Manager
Click Sql Server Network Configuration
Click Protocols for SQLExpress
Double click TCP/IP and click IP adrress tab
Go to the end till you see IP ALL
Ensure that you see port number 1433 is configured under TCP Port under IPALL header.
If not configured, enter 1433 port and click Apply.
You need to restart the MS sql server and try now and it should work.
Hope this will solve it.

Can't connect to cassandra : NodeContext killing all pooled connections for session

When I try to connect to cassandra within my java application I receive the exception at the end of this message. I am using pelops library to access database. Database is working on linux and my development environment is on windos 7. Intresting line is
WARNING: 10.0.0.7 NodeContext killing all pooled connections for session 44
10.0.0.7 is the IP of the cassandra node. And I can connect this node with cassandra-cli. After a few hours of googling I decided to ask, what i am doing wrong?
Complete stack trace is below.
SEVERE: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused: connect
at org.apache.thrift.transport.TSocket.open(TSocket.java:185)
at org.wyki.cassandra.pelops.ThriftPool$Connection.open(ThriftPool.java:329)
at org.wyki.cassandra.pelops.ThriftPool$NodeContext.createConnection(ThriftPool.java:438)
at org.wyki.cassandra.pelops.ThriftPool$NodeContext.access$5(ThriftPool.java:429)
at org.wyki.cassandra.pelops.ThriftPool$NodeContext$1.run(ThriftPool.java:494)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at org.apache.thrift.transport.TSocket.open(TSocket.java:180)
... 7 more
WARNING: 10.0.0.7 NodeContext killing all pooled connections for session 44
"Connection refused" means that Cassandra isn't listening on the interface you're connecting to. By default Cassandra listens on port 9160 on localhost. You will need to change that if you want to connect externally; read the comments for ThriftAddress in the configuration file.
Pelops isn't doing anything remotely tricky when it comes to making connections to Cassandra so it seems very unlikely it's Pelops specific.
I've just had a quick look at the Hector connection code and it looks pretty much the same:
https://github.com/rantav/hector/blob/master/core/src/main/java/me/prettyprint/cassandra/connection/HThriftClient.java
The cassandra-cli code looks pretty much the same as well:
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/cli/CliMain.java#L57
p.s. Cassandra should not be configured to listen on 0.0.0.0. See the "Why can't I make Cassandra listen on 0.0.0.0 (all my addresses)?" on the Cassandra FAQ.
It seems that this is a problem with pelops, which is a library on top of cassandra's thrift client. It has some problems for connection to Cassandra working on linux and client on a windows machine.
I've got the same exception connecting with "any" client to cassandra remotely:
ConnectException: Connection refused
Looking through SO I couldn't find a quick solution for that, just reading carefully through cassandra docs and comments within cassandra.yaml - they are very handy!
So for me worked following:
change rpc_address value to the hostname or ipaddress you are using to connect to the cassandra instance with the client

Categories

Resources