Bug #64983 5.1.19 not working with JBoss AS 4.2.3.GA
Submitted: 14 Apr 2012 23:08 Modified: 1 May 2012 3:37
Reporter: Kenneth Christensen Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.19 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any
Tags: regression

[14 Apr 2012 23:08] Kenneth Christensen
Description:
5.1.19 is not working together with JBoss AS 4.2.3 (no problems with 5.1.18):

5.1.19 error (MySQLNonTransientConnectionException: Bad handshake):

2012-04-15 00:47:21,362 WARN  [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Bad handshake)
	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.getConnection(InternalManagedConnectionPool.java:264)
...
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Bad handshake
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

How to repeat:
Replace 5.1.18 with 5.1.19 and start the JBoss AS 4.2.3.GA server
[16 Apr 2012 13:23] Alexander Soklakov
Hello Kenneth!

Thanks for your report. But I cannot repeat this on my system. Could you provide more details: OS, jvm version, mysql server version, datasource config?
[20 Apr 2012 8:24] Eric Cartman
I have the same problem with the 5.1.19 version of the Java connector together with JBoss 6.1.0 on a 64 bit RHEL. The MySQL server version is 5.5.12 and my datasource configuration file looks as follows:

<?xml version="1.0" encoding="UTF-8"?>

<datasources>
	<local-tx-datasource>
		<jndi-name>foo</jndi-name>
		<connection-url>jdbc:mysql://localhost/bar?useUnicode=true&amp;characterEncoding=utf8</connection-url>
		<driver-class>com.mysql.jdbc.Driver</driver-class>
		<user-name>user</user-name>
		<password>password</password>

		<min-pool-size>5</min-pool-size>
		<max-pool-size>150</max-pool-size>

		<exception-sorter-class-name>com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter</exception-sorter-class-name>
		<valid-connection-checker-class-name>com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker</valid-connection-checker-class-name>
	</local-tx-datasource>
</datasources>

This must be a regression as everything was working fine in version 5.1.18 and also in earlier versions of the connector. I haven't changed the datasource configuration or MySQL server setup at all, just updated the connector to 5.1.19 and it does no longer work.
[20 Apr 2012 8:46] Alexander Soklakov
Hi Eric,

Could you get tcpdump of that bad handshake? I still cannot repeat the problem.
[20 Apr 2012 9:25] Eric Cartman
Unfortunately i cannot get such a dump, i do not even have root access on that machine. If i can help by providing some other information, please let me know.
[20 Apr 2012 10:01] Alexander Soklakov
Eric,

One question: do you use "old-passwords" option, i.e. old-style password encryption?

I've got "Bad handshake" with that one. It looks like bug in MysqlOldPasswordPlugin implementation.
[20 Apr 2012 20:31] Kenneth Christensen
I'm not using the "old passwords" option:

| old_passwords                                     | OFF

The MySQL version is 5.5.21 and I have only tested it on my development machine which is a Mac OS X 10.7.3 and JDK 1.6.0_31.

Here is my datasource:

<datasources>
    <local-tx-datasource>
        <jndi-name>EgenkontrolDS</jndi-name>
        <connection-url>jdbc:mysql://localhost:3306/egenkontrol</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>

        <user-name><user></user-name>
        <password><password></password>

        <min-pool-size>1</min-pool-size>
        <max-pool-size>10</max-pool-size>

        <!-- The number of prepared statements per connection to be kept open and reused in subsequent requests. They are stored in a LRU cache. The default is 0 (zero), meaning no cache. -->
        <prepared-statement-cache-size>50</prepared-statement-cache-size>
        
        <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
        <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>

        <!-- Checks the MySQL error codes and messages for fatal errors -->
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    </local-tx-datasource>
</datasources

Above works fine with 5.1.18 but not with 5.1.19.
[23 Apr 2012 8:37] Alexander Soklakov
Kenneth,

What is the length of password hash (select length(Password) from mysql.user where User='youruser')? Is it 16 or 41 bytes long?
[23 Apr 2012 8:42] Kenneth Christensen
Alexander,

The length of the password hash is 16 bytes long.
[23 Apr 2012 9:08] Alexander Soklakov
Kenneth,

So, you do use old-style password hash which requires "mysql_old_password" plugin during handshake. Try to replace 16-bytes hash with 41-bytes one (see http://dev.mysql.com/doc/refman/5.5/en/password-hashing.html).
[23 Apr 2012 9:26] Kenneth Christensen
Looks like it's working now, after setting the password to a 41 bytes long hash.

Thanks.
[23 Apr 2012 9:36] Alexander Soklakov
Good, so this is a bug in MysqlOldPasswordPlugin.
[1 May 2012 3:37] John Russell
Added to changelog for 5.1.20: 

Using Connector/J 5.1.19 in combination with JBoss could result in an
error while establishing a connection:
MySQLNonTransientConnectionException: Bad handshake. This issue
occurred when using the old-style password hash, which requires the
mysql_old_password plugin during handshake. A workaround was to
replace the 16-byte hash with a 41-byte one, as explained in .