API endpoints timing out

I'm hosting a auth server on railway and the API just becomes unresponsive if I hit one of better-auth endpoints with my http client (httpie) locally it works fine and it logs correctly:
<-- POST /api/auth/sign-up/email
checking client timeout
connecting new client
new client connected
pulse queue
no queued requests
2025-03-11T02:25:22.421Z INFO [Better Auth]: Sign-up attempt for existing email: [email protected]
--> POST /api/auth/sign-up/email 422 776ms
remove idle client
<-- POST /api/auth/sign-up/email
checking client timeout
connecting new client
new client connected
pulse queue
no queued requests
2025-03-11T02:25:22.421Z INFO [Better Auth]: Sign-up attempt for existing email: [email protected]
--> POST /api/auth/sign-up/email 422 776ms
remove idle client
(I added logs: console.log to the db config because I thought something was hanging there) but on railway it hangs infinitely and crashes my api with a mem leak
Started server: http://localhost:8080
Redis connected
Redis ready
<-- GET /
--> GET / 200 0ms
<-- GET /api/auth/sign-up/email
Started server: http://localhost:8080
Redis connected
Redis ready
<-- GET /
--> GET / 200 0ms
<-- GET /api/auth/sign-up/email
worth mentioning i'm using bun + hono setup, there's nothing else in the api, just better-auth. This is my auth.ts:
import { betterAuth } from "better-auth"
import { openAPI } from "better-auth/plugins"
import { Pool } from "pg"
import { Redis } from "ioredis"

const redis = new Redis(process.env.REDIS_URL as string)
.on("error", (err) => {
console.error("Redis connection error:", err)
})
.on("connect", () => {
console.log("Redis connected")
})
.on("ready", () => {
console.log("Redis ready")
})

export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
plugins: [openAPI()],
database: new Pool({
connectionString: process.env.DATABASE_URL,
log: console.log
}),
secondaryStorage: {
get: async (key) => {
const value = await redis.get(key)
return value ? JSON.stringify(value) : null
},
set: async (key, value, ttl) => {
if (ttl) await redis.set(key, value, "EX", ttl)
else await redis.set(key, value)
},
delete: async (key) => {
await redis.del(key)
},
},
})
import { betterAuth } from "better-auth"
import { openAPI } from "better-auth/plugins"
import { Pool } from "pg"
import { Redis } from "ioredis"

const redis = new Redis(process.env.REDIS_URL as string)
.on("error", (err) => {
console.error("Redis connection error:", err)
})
.on("connect", () => {
console.log("Redis connected")
})
.on("ready", () => {
console.log("Redis ready")
})

export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
plugins: [openAPI()],
database: new Pool({
connectionString: process.env.DATABASE_URL,
log: console.log
}),
secondaryStorage: {
get: async (key) => {
const value = await redis.get(key)
return value ? JSON.stringify(value) : null
},
set: async (key, value, ttl) => {
if (ttl) await redis.set(key, value, "EX", ttl)
else await redis.set(key, value)
},
delete: async (key) => {
await redis.del(key)
},
},
})
2 Replies
Medim
MedimOP4w ago
after some time it crashes because of memory
No description
Medim
MedimOP4w ago
those spikes are when I hit an auth endpoint and it's also being pinned by something to 1vcpu maybe bun?

Did you find this page helpful?