[CONJ-905] NullPointerException when using unix sockets on NixOS Created: 2021-11-28  Updated: 2021-12-20  Resolved: 2021-12-20

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 2.6.0
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Johannes Spangenberg Assignee: Diego Dupin
Resolution: Not a Bug Votes: 0
Labels: crash
Environment:

Operating System: NixOS 21.05
Application: Flyway 7.5.4
Database: MariaDB 10.5.13



 Description   

The JDBC connector throws a NullPointerException when I try to use it on NixOS with unix domain sockets. I don't know the background of this problem, but I think I should at least get a better error message. Maybe it is some issue with the native part for Unix domain sockets? NixOS is special because you cannot find the .so files at the usual places.

I noticed another strange aspect regarding this issue. As you can see in the stracktrace, the exception is thrown in setAutoCommit. I would usually expect that this method is only called after authentication. However, I doubt that any authentication took place. In my example below, the user and database are both unknown to the database server. So, if there were any authentication, it should have been rejected by the database server. (I get the same result if I use a valid username and database.)

DEBUG: Unable to load config file: /nix/store/ic3asrlznl35bfmiyysbk788rjmsv9mc-flyway-7.5.4/share/conf/flyway.conf
DEBUG: Unable to load config file: /var/empty/flyway.conf
DEBUG: Unable to load config file: /flyway.conf
DEBUG: Loading config file: /nix/store/3zjd120k15dnnmc38da65nqry0zbc3qs-flyway.conf
DEBUG: Directory for Jdbc Drivers not found: /nix/store/ic3asrlznl35bfmiyysbk788rjmsv9mc-flyway-7.5.4/share/drivers
DEBUG: Adding location to classpath: /nix/store/3gw3hnplqm5q01563404z4vnfr6r456i-mariadb-connector-java-2.7.4/share/java/mariadb-java-client.jar
DEBUG: Adding location to classpath: /nix/store/sm2n008sc1jrfv987yx7sysqa5c6sd21-jna-5.10.0/share/java/jna.jar
DEBUG: Adding location to classpath: /nix/store/sm2n008sc1jrfv987yx7sysqa5c6sd21-jna-5.10.0/share/java/jna-platform.jar
DEBUG: Using configuration:
DEBUG: flyway.configFiles -> /nix/store/3zjd120k15dnnmc38da65nqry0zbc3qs-flyway.conf
DEBUG: flyway.jarDirs -> /nix/store/3gw3hnplqm5q01563404z4vnfr6r456i-mariadb-connector-java-2.7.4/share/java/:/nix/store/sm2n008sc1jrfv987yx7sysqa5c6sd21-jna-5.10.0/share/java/
DEBUG: flyway.locations -> filesystem:/nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations
DEBUG: flyway.url -> jdbc:mariadb:///somedb?localSocket=/run/mysqld/mysqld.sock
DEBUG: flyway.user -> myuser
DEBUG: flyway.validateMigrationNaming -> true
DEBUG: flyway.validateOnMigrate -> true
DEBUG: Scanning for classpath resources at 'classpath:db/callback' ...
DEBUG: Determining location urls for classpath:db/callback using ClassLoader java.net.URLClassLoader@108c4c35 ...
DEBUG: Unable to resolve location classpath:db/callback.
Flyway Community Edition 7.5.4 by Redgate
DEBUG: AWS SDK available: false
DEBUG: Google Cloud Storage available: false
DEBUG: Scanning for filesystem resources at '/nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations'
DEBUG: Scanning for resources in path: /nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations (/nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations)
DEBUG: Found filesystem resource: /nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations/V1__Initial_Schema.sql
DEBUG: Validating V1__Initial_Schema.sql
ERROR: Unexpected error
java.lang.NullPointerException: Cannot invoke "org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(String, String, int)" because "this.exceptionFactory" is null
  at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.cmdPrologue(AbstractQueryProtocol.java:1926)
  at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:249)
  at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getAutoIncrementIncrement(AbstractQueryProtocol.java:1624)
  at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:353)
  at org.mariadb.jdbc.MariaDbStatement.executeUpdate(MariaDbStatement.java:625)
  at org.mariadb.jdbc.MariaDbConnection.setAutoCommit(MariaDbConnection.java:707)
  at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnectionFromDriver(DriverDataSource.java:329)
  at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnection(DriverDataSource.java:289)
  at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:59)
  at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:69)
  at org.flywaydb.core.Flyway.execute(Flyway.java:507)
  at org.flywaydb.core.Flyway.migrate(Flyway.java:165)
  at org.flywaydb.commandline.Main.executeOperation(Main.java:223)
  at org.flywaydb.commandline.Main.main(Main.java:144)



 Comments   
Comment by Johannes Spangenberg [ 2021-11-29 ]

Looks like there was some issue prevented me from replacing the MariaDB client library and JNA. So the exception above has still used version 2.6.0 of the MariaDB connector and some older version of JNA. This is the exception I got with 2.7.4. Looks much better already. Only “Could not connect to named pipe 'null'” looks strange.

flyway[1079]: DEBUG: Unable to load config file: /nix/store/xbjxjlhyndy30a71spn7f2q9lf3x7ns8-flyway_custom-7.13.0/share/conf/flyway.conf
flyway[1079]: DEBUG: Unable to load config file: /var/empty/flyway.conf
flyway[1079]: DEBUG: Unable to load config file: /flyway.conf
flyway[1079]: DEBUG: Loading config file: /nix/store/s283137wqxbs257g20ficwvx7dg3j6fm-flyway.conf
flyway[1079]: DEBUG: Directory for Jdbc Drivers not found: /nix/store/xbjxjlhyndy30a71spn7f2q9lf3x7ns8-flyway_custom-7.13.0/share/drivers
flyway[1079]: DEBUG: Adding location to classpath: /nix/store/3gw3hnplqm5q01563404z4vnfr6r456i-mariadb-connector-java-2.7.4/share/java/mariadb-java-client.jar
flyway[1079]: DEBUG: Adding location to classpath: /nix/store/sm2n008sc1jrfv987yx7sysqa5c6sd21-jna-5.10.0/share/java/jna.jar
flyway[1079]: DEBUG: Adding location to classpath: /nix/store/sm2n008sc1jrfv987yx7sysqa5c6sd21-jna-5.10.0/share/java/jna-platform.jar
flyway[1079]: DEBUG: Using configuration:
flyway[1079]: DEBUG: flyway.configFiles -> /nix/store/s283137wqxbs257g20ficwvx7dg3j6fm-flyway.conf
flyway[1079]: DEBUG: flyway.jarDirs -> /nix/store/3gw3hnplqm5q01563404z4vnfr6r456i-mariadb-connector-java-2.7.4/share/java/:/nix/store/sm2n008sc1jrfv987yx7sysqa5c6sd21-jna-5.10.0/share/java/
flyway[1079]: DEBUG: flyway.locations -> filesystem:/nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations
flyway[1079]: DEBUG: flyway.url -> jdbc:mariadb:///mail?localSocket=/run/mysqld/mysqld.sock
flyway[1079]: DEBUG: flyway.user -> flyway
flyway[1079]: DEBUG: flyway.validateMigrationNaming -> true
flyway[1079]: DEBUG: flyway.validateOnMigrate -> true
flyway[1079]: DEBUG: Scanning for classpath resources at 'classpath:db/callback' ...
flyway[1079]: DEBUG: Determining location urls for classpath:db/callback using ClassLoader java.net.URLClassLoader@421faab1 ...
flyway[1079]: DEBUG: Unable to resolve location classpath:db/callback.
flyway[1079]: DEBUG: AWS SDK available: false
flyway[1079]: DEBUG: Google Cloud Storage available: false
flyway[1079]: DEBUG: Scanning for filesystem resources at '/nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations'
flyway[1079]: DEBUG: Scanning for resources in path: /nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations (/nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations)
flyway[1079]: DEBUG: Found filesystem resource: /nix/store/rrf7v6zqzarsxlkfndlsdg1zjxd4fawk-sql-migrations/V1__Initial_Schema.sql
flyway[1079]: DEBUG: Validating V1__Initial_Schema.sql
mysql-start[1042]: 2021-11-29 21:38:41 7 [Warning] Access denied for user ''@'localhost' to database 'mail'
flyway[1079]: ERROR: Unexpected error
flyway[1079]: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database (jdbc:mariadb:///mail?localSocket=/run/mysqld/mysqld.sock) for user 'flyway': Could not connect to named pipe 'null' : (conn=7) Access denied for user ''@'localhost' to database 'mail'
flyway[1079]: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---
flyway[1079]: SQL State  : 08000
flyway[1079]: Error Code : -1
flyway[1079]: Message    : Could not connect to named pipe 'null' : (conn=7) Access denied for user ''@'localhost' to database 'mail'
flyway[1079]:   at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:66)
flyway[1079]:   at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:68)
flyway[1079]:   at org.flywaydb.core.Flyway.execute(Flyway.java:502)
flyway[1079]:   at org.flywaydb.core.Flyway.migrate(Flyway.java:168)
flyway[1079]:   at org.flywaydb.commandline.Main.executeOperation(Main.java:256)
flyway[1079]:   at org.flywaydb.commandline.Main.main(Main.java:177)
flyway[1079]: Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to named pipe 'null' : (conn=7) Access denied for user ''@'localhost' to database 'mail'
flyway[1079]:   at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73)
flyway[1079]:   at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:188)
flyway[1079]:   at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1367)
flyway[1079]:   at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:635)
flyway[1079]:   at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:150)
flyway[1079]:   at org.mariadb.jdbc.Driver.connect(Driver.java:89)
flyway[1079]:   at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnectionFromDriver(DriverDataSource.java:268)
flyway[1079]:   at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnection(DriverDataSource.java:232)
flyway[1079]:   at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:51)
flyway[1079]:   ... 5 more
flyway[1079]: Caused by: java.sql.SQLSyntaxErrorException: (conn=7) Access denied for user ''@'localhost' to database 'mail'
flyway[1079]:   at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:62)
flyway[1079]:   at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:192)
flyway[1079]:   at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.authenticationHandler(AbstractConnectProtocol.java:778)
flyway[1079]:   at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createConnection(AbstractConnectProtocol.java:555)
flyway[1079]:   at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1364)
flyway[1079]:   ... 11 more

Comment by Johannes Spangenberg [ 2021-11-30 ]

It seems to work now if I supply the right credentials. Since the issue does not seem to exist in 2.7.4 anymore, I think you can close the ticket. It is strange that it has reported the socket as being null in the error message in my last comment, but I think that is not a big issue. Thanks.

Comment by Diego Dupin [ 2021-12-20 ]

closing as requested

Generated at Thu Feb 08 03:19:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.