0

I have one small app that use fastapi. The problem is when I deploy it to my server and trying to make a post request to route which contains some database operations, it just stuck and gives me 504 error. But on my local machine it working well.

Here is how my db connecting:

app.add_event_handler("startup", tasks.create_start_app_handler(app))
app.add_event_handler("shutdown", tasks.create_stop_app_handler(app))

I tried to revert db connection from startup application to creation of this connection with closing it in different route to test and its worked. Like:

@app.get("/")
async def create_item():
    engine = create_engine(
        DB_URL
    )
    SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

    Base = declarative_base()

    t = engine.execute('SELECT * FROM auth_user').fetchone()

    engine.dispose()
    return t

How it's depend on events? Versions of postgresql are different, but I don't think it's because of it.

Currently I have deployment with 2 pods running in it. When I use psql command I can connect normally. So it only stuck in application, not it pod.

1 Answer 1

0

If somebody finds same, I fixed it by updating pgpoll from 4.2.2 to latest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.