We had an issue with hibernate connections failed to close. We used separated connections for each Dao and all of them stayed open even we called session.close() in after method for each used Dao and checked that they were really executed. The connections have died 2h after the test run, for each test we left open 5-10 connection and because the connection limit to the DB was really small (100 connection) we were unable to run tests as often as we wished.

Temporally solution was to manually kill the connections using putty. To do this we had to connect to the machine where the DB is running and now not connect to the DB but to postgres. Now we can list the living connections with query “SELECT * FROM pg_stat_activity;”. To kill the connections one by one use query “SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid=/*the pid of the connection you want to kill*/;”. It’s much faster if you can write a simple query to find all the connections you want to kill and kill them all with one query. Need to be careful not to kill important connections what not your test opened, including your current connection to the DB. Useful information about connection kill can be found here.

Final solution was to find out what was the reason that the session was not closed. To find out we checked the setting all programs we used to open the connection with the DB (VPN, drivers, etc.). At the end we find out that the reason behind the issue was a third-party security program’s firewall what detected the close call as an attack and blocked. After turning off the firewall part of the program the issue was solved, no more connection was left open after test runs.

Similar Posts from the author: