What is responsible for this db-sync 'finalizer failure' message?

I had this problem since yesterday too, so I spent many a hours to figure out whats going “wrong”. There are a couple of reports regarding this, but nobody has been able to figure out what is happening yet.

This is not an issue, the message is being created from redundant garbage collection calls to close the connection to the database. Turns out org-roam manually closes the connection to the database when doing a sync

emacsql-close(#<emacsql-sqlite-builtin-connection emacsql-sqlite-builtin-connection-15920964e2c2>)
  org-roam-db--close()
  org-roam-db-sync((4))

But emacsql-close is also called as part of an automatic finalizer call

(defun emacsql-register (connection)
  "Register CONNECTION for automatic cleanup and return CONNECTION."
  (prog1 connection
    (oset connection finalizer
          (make-finalizer (lambda () (emacsql-close connection))))))

And it is this finalizer call that fails - because there is nothing to close - the connection has already been closed diligently manually by org-roam, there is no loose thread to clean up.

You can debug the close function to find out more for yourself-

(cl-defmethod emacsql-close ((connection emacsql-sqlite-builtin-connection))
  (message "running fn %s" (current-time))
  (condition-case err
      (if (oref connection handle)
          (progn
            (message "Closing SQLite connection handle: %s" (oref connection handle))
            (sqlite-close (oref connection handle))
            (oset connection handle nil)
            (message "SQLite connection closed successfully."))
        (message "No active handle to close for connection: %s" connection))
    (error
     (message "Error while closing SQLite connection: %s" err)))
  ;; Log backtrace
  (message "Backtrace:\n%s" (with-output-to-string (backtrace))))

If the message annoys you a lot you can modify this function to gracefully handle the case when (oref connection handle) is nil, that would suppress the message.