This simple project demonstrates a mariadb-connector-j bug where Connection.isValid does not obey the passed in timeout if the network is down. Instead of obeying the timeout value, the call will hang until the socket timeout is hit. To reproduce the problem you will need to be able to simulate network failure. The instructions below describe how to achieve this with Clumsy, which is only available on Windows.
- boot up a local mariadb instance.
- download Clumsy, which will be used to simulate network failure.
- open Clumsy, then set the filter to
tcp.DstPort == 3306 or tcp.SrcPort == 3306 or udp.DstPort == 3306 or udp.SrcPort == 3306
to block traffic to your local mariadb instance on port 3306. UnderFunctions
, checkDrop
and setChance
to 100%. Do not hit start yet. - set the USER and PASSWORD environment variables to match your mariadb instance.
- the code will connect to mariadb and then prompt you to disable network traffic to mariadb and wait for 15 seconds. Run the test, and when prompted, hit
Start
in clumsy to begin blocking traffic to mariadb. - the code will throw an exception, showing that the duration of the isValid call was 10 seconds (the socket timeout value) instead of 2 seconds (the timeout value passed to isValid).