I am using django-grpc-framework in my django rest project. I setup a grpc service to get some user information from this project using grpc server. This grpc service is running using kubernetes, and after a while of running, I get the following error:
django.db.utils.InterfaceError: connection already closed
I restart the deployment and the issue goes away.
I recently added the following line after every grpc service method:
django.db.close_old_connections()
but now I see that some rpc calls take 20 ms to connect to the database, and this is slowing the response time. Is there any other way to fix my problem without causing long response times.