vapor-community / heroku-buildpack

Heroku buildpack for Swift
BSD 3-Clause "New" or "Revised" License
141 stars 58 forks source link

updated to latest buildpack and heroku-20: No available connections on this event loop, creating a new one [database-id: psql] #57

Closed cacaosteve closed 3 years ago

cacaosteve commented 3 years ago

The only Add-on I have is Heroku Postgres. All I know is it was working before and now it doesn't work. On the deploy, I updated from heroku-18 to heroku-20 and then to this latest buildpack.

[ DEBUG ] No available connections on this event loop, creating a new one [database-id: psql] (AsyncKit/ConnectionPool/EventLoopConnectionPool.swift:202) [ DEBUG ] Application shutting down (Vapor/Application.swift:124) Fatal error: Error raised at top level: connection reset (error set): Connection refused (errno: 111): file Swift/ErrorType.swift, line 200 Current stack trace: 0 libswiftCore.so 0x00007fac95152530 swift_reportError + 50 1 libswiftCore.so 0x00007fac951c6050 _swift_stdlib_reportFatalErrorInFile + 115 2 libswiftCore.so 0x00007fac94eab915 + 1399061 3 libswiftCore.so 0x00007fac94eab557 + 1398103 4 libswiftCore.so 0x00007fac94eabaf2 + 1399538 5 libswiftCore.so 0x00007fac94ea9f90 assertionFailure(:_:file:line:flags:) + 517 6 libswiftCore.so 0x00007fac94f136a6 + 1824422 7 0x000055e3e900e3f1 + 7885809 8 libc.so.6 0x00007fac93f6afc0 __libc_start_main + 243 9 0x000055e3e89ab6ae + 1189550 0x7fac94d2e3bf 0x7fac94eaa1a2 0x7fac94f136a5 0x55e3e900e3f0, main at /tmp/build_ddd998a5/:0 0x7fac93f6b0b2 0x55e3e89ab6ad 0xffffffffffffffff Illegal instruction

vzsg commented 3 years ago

The actual error in that printout is:

Fatal error: Error raised at top level: connection reset (error set): Connection refused (errno: 111)

You should focus on this line. Apparently the application could not connect to the database for some reason.

I doubt that it's actually related to the buildpack or the heroku-20 stack (considering the Vapor drivers are built from the ground up with NIO and don't depend on the system libraries), but you could nevertheless try downgrading the stack to heroku-16 or heroku-18.

cacaosteve commented 3 years ago

Thank you for your help, vzsg. As you said, I used DATABASE_URL environment variable and you helped me turn the dyno off and on again.

if let databaseURL = Environment.get("DATABASE_URL"),
   var config = PostgresConfiguration(url: databaseURL)
{
    config.tlsConfiguration = TLSConfiguration.forClient(certificateVerification: .none)
    app.databases.use(.postgres(configuration: config), as: .psql)
} else {
    app.databases.use(.postgres(
        hostname: Environment.get("DATABASE_HOST") ?? "localhost",
        username: Environment.get("DATABASE_USERNAME") ?? "postgres",
        password: Environment.get("DATABASE_PASSWORD") ?? "password",
        database: Environment.get("DATABASE_NAME") ?? "spark"
    ), as: .psql)
}