I guess, the reason is that usestd does not use threads, but httpx (the httpbeast fork that prologue uses) does.
As far as i understand the theadvar pragma, every thread gets its own pool variable, but my guess ist that the database connection is not correctly initialized for each thread.
the docs https://nim-lang.org/docs/manual.html#threads-threadvar-pragma state that: "(Every thread local variable needs to be replicated at thread creation.)"
So you somehow must do this:
var foo {.threadvar.}: ref bool
template fixFoo() =
echo "define foo for: ", getThreadId()
foo = new(bool)
foo[] = false
proc faa() {.thread.} =
fixFoo()
echo foo[]
var th1: Thread[void]
var th2: Thread[void]
createThread(th1, faa)
createThread(th2, faa)
fixFoo()
echo foo[]
joinThreads(th1, th2)