datahike

silian 2025-04-29T23:44:40.643389Z

Hi team. (0.6.1594) I am having to kill REPL and start up again after changing Wifi network I think. If I try to transact from localhost web app after closing laptop, I get I/O error, reproduced in thread. I think this came up before.

whilo 2025-05-08T19:29:14.073779Z

Maybe sqlite closes the connection in this case for some reason. How do you address the sqlite database locally?

silian 2025-05-08T19:30:02.173729Z

I am always just connected to the prod db.

silian 2025-05-08T19:30:41.414449Z

(I am very lazy, what I'm making is very early, no users.)

whilo 2025-05-08T19:30:51.777349Z

That is fine.

whilo 2025-05-08T19:31:11.490519Z

Since you mention network changes I guess that somehow the connection becomes invalidated with a new IP.

whilo 2025-05-08T19:31:21.689389Z

Either by sqlite, or maybe by datahike.

whilo 2025-05-08T19:31:42.931729Z

Since you get an I/O error I think it is JDBC/sqlite.

silian 2025-05-08T19:32:14.597599Z

The prod db is postgres on Heroku. JDBC uses sqlite in this instance?

whilo 2025-05-08T19:32:34.661409Z

Oh, sorry, you use postgres.

silian 2025-05-08T19:32:57.507429Z

Yes, it's a postgres db

whilo 2025-05-08T19:33:28.070089Z

I think it might just be a problem that the underlying JDBC connection breaks during network changes. You will have to reconnect in this case with datahike.

whilo 2025-05-08T19:33:45.198409Z

The error could be better handled though. @alekcz360 have you experienced this as well?

silian 2025-05-08T19:34:23.412659Z

Also—maybe this is relevant—I never release the conn after connecting to it in various functions.

silian 2025-05-08T19:34:46.851999Z

Perhaps this is bad practice, I don't really know.

silian 2025-05-08T19:35:09.471679Z

Thanks for the input, whilo!

whilo 2025-05-08T19:36:23.032519Z

You don't have to release unless your network connection changes or you don't want to interact with the database anymore. It is fine to hold onto connections in general. JDBC might be more restrictive though, so in this case you have to satisfy JDBC connection management.

alekcz 2025-05-08T19:37:15.330479Z

I've never had this issue. And we've been using Postgres for a while. I'll look through the stack trace shortly

1
alekcz 2025-05-08T19:38:46.002599Z

Is there a previous error or warning before this error?

silian 2025-05-08T19:41:50.213679Z

I don't think so. Usually it happens like this: I am working on my project after jacking-in. After a while, I close my laptop and go to new coffeeshop. I open laptop and try to take an action in my web project from localhost. (Like submit something new to the db.) The web app hangs and then finally gives 500 error with I/O error

silian 2025-05-08T19:42:29.187369Z

To solve the problem, I have to disconnect and close the REPL and start over again.

alekcz 2025-05-08T19:58:24.243399Z

@feedmyinbox02_clojuri I think this is Postgres. I connected on one WiFi network to postgres, when I change net works and run a command it hangs.

alekcz 2025-05-08T19:59:10.845269Z

It's been hanging for like 5 min now

alekcz 2025-05-08T20:08:34.104729Z

could not receive data from server: Operation timed out
SSL SYSCALL error: Operation timed out
The connection to the server was lost. Attempting reset: Succeeded.
psql (17.4, server 16.6 (Debian 16.6-1.pgdg120+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_128_GCM_SHA256, compression: off, ALPN: none)

alekcz 2025-05-08T20:10:34.191209Z

I'll look into this when I do the next cut. I want to move away from C3p0 to Hikari

silian 2025-05-08T20:10:43.383719Z

Wow we discovered a new postgres bug?

alekcz 2025-05-08T20:10:53.444069Z

I think it's too long a timeout

silian 2025-05-08T20:10:54.741659Z

(By we I mean you, lol)

alekcz 2025-05-08T20:11:04.983199Z

When the time out expired it reconnected easily

silian 2025-05-08T21:40:33.054349Z

it's possible to set timeout in datahike config?

silian 2025-05-09T00:05:06.813279Z

After startup I also repeatedly get this:

; org.postgresql.util.PSQLException: FATAL: too many connections for role "u23q0bq15ogiru"
;               SQLState: "53300"
;              errorCode: 0
;     serverErrorMessage: #object[org.postgresql.util.ServerErrorMessage 0x46ad04f0 "FATAL: too many connections for role \"u23q0bq15ogiru\""]
This repeats maybe 100 or more times before I interrupt. And start over. A lot of these "at startup" errors that happen once a day. Here is fuller pastebin: https://pastebin.com/PyebYStJ

silian 2025-05-09T00:05:44.802849Z

In the output REPL (Calva) the error just repeats until I kill the server and start over.

silian 2025-05-09T00:09:30.144949Z

Hmm, this is a new one—just received this for the first time:

HTTP ERROR 500 clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {} {}
URI:	/retract-user/i+dont+know+what+the+hell
STATUS:	500
MESSAGE:	clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {} {}
SERVLET:	-
CAUSED BY:	clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {} {}
CAUSED BY:	java.util.concurrent.ExecutionException: clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {}
CAUSED BY:	clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {}
CAUSED BY:	clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {}
CAUSED BY:	clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {}
CAUSED BY:	clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {}
CAUSED BY:	clojure.lang.ExceptionInfo: Connections could not be acquired from the underlying database! {}
CAUSED BY:	java.sql.SQLException: Connections could not be acquired from the underlying database!
CAUSED BY:	com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
CAUSED BY:	org.postgresql.util.PSQLException: FATAL: too many connections for role "u23q0bq15ogiru"

alekcz 2025-05-09T12:17:35.366889Z

@feedmyinbox02_clojuri this one usually happens where there aren't enough available connection. The connection pool usually tries to reserve 15 connection. So if they aren't 15 available you'll get this error. It looks like in yours datahike has requested more threads than it should be allow. Are there any REPLs hanging on to the threads. Or maybe the hot reloading is creating multiple instances?

silian 2025-05-09T20:25:03.616469Z

I don't use hot reloading or figwheel. Sometimes I forget to stop a server before terminating an nREPL so perhaps that is causing it.

silian 2025-04-29T23:45:03.626859Z

Server error:

HTTP ERROR 500 clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo: An I/O error occurred while sending to the backend. {} {}
URI:	/make-user
STATUS:	500
MESSAGE:	clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo: An I/O error occurred while sending to the backend. {} {}
SERVLET:	-
CAUSED BY:	clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo: An I/O error occurred while sending to the backend. {} {}
CAUSED BY:	java.util.concurrent.ExecutionException: clojure.lang.ExceptionInfo: An I/O error occurred while sending to the backend. {}
CAUSED BY:	clojure.lang.ExceptionInfo: An I/O error occurred while sending to the backend. {}
CAUSED BY:	org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
CAUSED BY:	java.net.SocketException: Operation timed out

silian 2025-04-29T23:47:46.905039Z

I don't want to vomit the entire stacktrace but here are select snippets relating to datahike:

clojure.lang.ExceptionInfo: clojure.lang.ExceptionInfo: An I/O error occurred while sending to the backend. {} {}
	at superv.async$throw_if_exception_.invokeStatic(async.cljc:93)
	at superv.async$throw_if_exception_.invoke(async.cljc:87)
	at datahike.tools$throwable_promise$reify__31338.deref(tools.cljc:85)
	at clojure.core$deref.invokeStatic(core.clj:2337)
	at clojure.core$deref.invoke(core.clj:2323)
	at datahike.api.impl$transact.invokeStatic(impl.cljc:40)
	at datahike.api.impl$transact.invoke(impl.cljc:40)
	at dental_practice_listing.persistence$create_user.invokeStatic(persistence.clj:91)
	at dental_practice_listing.persistence$create_user.invoke(persistence.clj:89)

silian 2025-05-08T05:24:24.276969Z

Sure, whilo. Here it is: https://pastebin.com/jn9RyT12

silian 2025-05-08T05:26:55.113909Z

Reconnect to the database? Hmm, I don't touch the code or the REPL in the interim. I am just closing my laptop and when I open next time, I am usually in a new physical location and new network.

whilo 2025-05-01T16:41:13.297389Z

Can you post it in a paste bin site maybe?

whilo 2025-05-01T16:46:35.066929Z

I suspect this might be a problem with hostnames changing during Wifi swap. Did you reconnect to the database in some way? I need to remove this config check anyway.

silian 2025-08-31T23:39:40.919969Z

Hi alek, just checking in. I continue to receive FATAL: too many connections for role using postgres on Heroku. I am not sure why so many connections. Can I ask you point to resource where I learn more?

silian 2025-08-31T23:41:53.047909Z

Is 15 a sufficient or normal number of connections for production system?

silian 2025-09-01T01:01:08.385459Z

To give some context, from my REPL connected to Heroku db, I ran (d/transact conn [[:db/add -1 :client "Langston Hughes"]]) In my output.repl this produced 20,000 lines of messages; here is sample: https://pastebin.com/raw/74bkvwkd