views:

458

answers:

1

I am using Hibernate 3 and I am facing a problem related to connections being closed.

I am using c3p0-0.9.1.2.jar and I checked onto the connections to database server opened by Hibernate, I found that there are established connections which are 5 in number; at some TCP ports of server (see below log).

But these established connections keeps on changing the TCP Ports on which they are established and thus releasing the earlier ports used by them, making these ports in TIME_WAIT state (rather than closing them).

This keeps on going and make the count in hundreds; for connections in TIME_WAIT condition.

I am not sure what is happening and why the ports are switching from Established to TIME_WAIT and none of the earlier ones are closing.

Below is the sample taken by running NETSTAT -ano|find "x.9" where x.9 is database server IP.

TCP     x.124.x.66:4379     x.124.x.9:1433      TIME_WAIT       0

TCP     x.124.x.66:4381     x.124.x.9:1433      TIME_WAIT       0

TCP     x.124.x.66:4382     x.124.x.9:1433      TIME_WAIT       0

TCP     x.124.x.66:4383     x.124.x.9:1433      TIME_WAIT       0

TCP     x.124.x.66:4384     x.124.x.9:1433      TIME_WAIT       0

TCP     x.124.x.66:4385     x.124.x.9:1433      TIME_WAIT       0

TCP     x.124.x.66:4386     x.124.x.9:1433      ESTABLISHED     5916

TCP     x.124.x.66:4387     x.124.x.9:1433      ESTABLISHED     5916

TCP     x.124.x.66:4388     x.124.x.9:1433      ESTABLISHED     5916

TCP     x.124.x.66:4389     x.124.x.9:1433      ESTABLISHED     5916

TCP     x.124.x.66:4390     x.124.x.9:1433      ESTABLISHED     5916

Hibernate.properties file used by me.

hibernate.c3p0.min_size=5
hibernate.c3p0.timeout=2
hibernate.c3p0.max_size=50
hibernate.c3p0.idle_test_period=10000
hibernate.connection.release_mode=auto

Thanks for help.

+2  A: 

TIME_WAIT is just the state when one or both sides have already terminated the connection, but it's not closed yet. Depending on your operation system, you can fine-tune how long connections should be in TIME_WAIT. So it doesn't mean anything bad, and it has no effect on performance as long as there are not too many of them preventing the creation of new connections.

On the other part of the question, when a client connects to a server specified by a hostname and a destination port, the connection on the client side will be assigned to a port. The reason for this is that a connection is identified by four things: destination host, destination port, source host, source port.

This is exactly what you see happening in your netstat output: you have 5 established connections created by the pool, and a few soon-to-be-closed one in the TIME_WAIT state. Each has its own source port dynamically assigned from a range. This is perfectly normal.

candiru