Java + Spring-boot keeps throwing unexpected SQLite exception

0

I have a backend application Java+Springboot based, with integrate a module that uses SQLite in order to perform some operations.

/**
* Called before every operation like the "doStuff method"
*/
public void connect(boolean autocommitMode) {
    try {
        Class.forName("org.sqlite.JDBC");
        System.out.println("Opening connection");
        this.dbConnection = DriverManager.getConnection("jdbc:sqlite:dbname.sqlite");
        this.dbConnection.setAutoCommit(autocommitMode);
        this.dbConnection.createStatement().execute("PRAGMA foreign_keys = ON");
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }
}

/**
* Called after every operation like the "doStuff method"
*/
public void closeConnection() {
    try {
        this.dbConnection.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
    
/**
* An example method that SOMETIMES cause the errors
*/
private PreparedStatement preparedStatement;

public boolean doStuff(String thing) {
    String query = "MY AWESOME QUERY";

    try {
        this.preparedStatement = this.dbConnection.prepareStatement(query);
        this.preparedStatement.setString(1, thing);
        ResultSet rs = this.preparedStatement.executeQuery();
        return rs.next();
    } catch (SQLException e) {
        e.printStackTrace();
        return false;
    }
}

Sometimes, without a specific behaviour or operation pattern, the application crashes and throwing an exception like that:

- org.sqlite.SQLiteException: [SQLITE_MISUSE]  Library used incorrectly (bad parameter or other API misuse)

-# A fatal error has been detected by the Java Runtime Environment:
#  SIGSEGV (0xb) at pc=0x00007fabc72c8d00, pid=1, tid=215

- # A fatal error has been detected by the Java Runtime Environment:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000703936c7, pid=10112, tid=15204

If I try to debug it on local machine, It throws only the third one

- # A fatal error has been detected by the Java Runtime Environment:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000703936c7, pid=10112, tid=15204

Instead, deployed on production machine (so dockerized and published), It throws all the error showed above.

On SQLite documentation, those behaviours are already reported, but the talk about low-level operation that we don't do here. Basically, our work flow can be summarize as that:

  1. Open the connection with the database
  2. Initiate the prapared statement
  3. Execute the query
  4. Close the connection

We noticed sometimes we do not close the statement after the query execution; even if we close it, the error still appears. Also, we observed that if we use an "already opened connection", the problem seems to be solved, but we can't assume this because its behavious is very... non-deterministic. So, we are going to prove it empirically.

Just another detail: our database connector class is a singleton, could this be a problem?

java
database
spring-boot
sqlite
asked on Stack Overflow Nov 4, 2020 by Mattia_B

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0