tomekw/hikari-cp

cannot make-datasource in barebones code, "The resultset is closed." ?

Closed this issue · 2 comments

I'm having an issue when i first try to use make-datasource with the message "The result set is closed". I believe something must be wrong somewhere in my environment or setup, as I see this problem connecting to two different postgres databases.

(ns my-ns.core
  (:require [clojure.java.jdbc :as j]
            [hikari-cp.core :refer :all]))

  (make-datasource
   {:jdbc-url  "jdbc:postgresql://127.0.0.1:5432/postgres"
    :pool-name "db-pool"
    :username  "me"
    :password  "super-secret"
;; I've also tried all different types of this:
    ;;:adapter            "postgresql"
    ;;:database-name      "postgres"
    ;;:server-name        "127.0.0.1"
    ;;:port-number        5432
    ;:register-mbeans    false

    ;:connection-test-query "select 1 as test"
    })

I'm getting this error:

 3. Unhandled clojure.lang.Compiler$CompilerException
    Error compiling form-init6568629681949614350.clj at (7:3)

 1. Caused by org.postgresql.util.PSQLException
    This ResultSet is closed.

I am sure something is binding to the database, because if i change my password to the incorrect "not-super-secret-password" I get an error such as below, as expected:

1. Caused by org.postgresql.util.PSQLException
FATAL: password authentication failed for user "me"

bypassing the pool works with no issue:

(j/query {:classname "org.postgresql.Driver"
           :subprotocol "postgresql"
           :subname "//127.0.0.1/postgres"
           :user "me"
           :password "super-secret"}
         "select current_timestamp")

;=> ({:current_timestamp #inst "2018-05-04T20:27:46.944078000-00:00"})

Relevant dependencies:

:dependencies [
               [org.clojure/clojure "1.9.0"]
               [org.clojure/java.jdbc "0.7.6"]
               [hikari-cp "2.4.0"]
               [postgresql/postgresql "9.3-1102.jdbc41"]
               ]

Any tips appreciated, thanks.

Ok, I think I may have figured out what was happening.

This comment on issue brettwooldridge/HikariCP/issues/1103 put me on the right track.

It turns out, with my postgres 10 system I wasn't able to use the artifact below, and needed to switch out to the org.postgresql one on maven.

Just swapping to the latest maven artifact seemed to make the issue above go away:

                 ;;[postgresql/postgresql "9.3-1102.jdbc41"]
                 [org.postgresql/postgresql "42.2.2"]

It seems strange because usually lein ancient notifies me when I have old stuff.... wasn't the case here because the owner switched.

I'll continue to do a bit of testing and close this if i'm sure the issue is gone. Thanks,

The comment above fixed my issue.