On Thu, Apr 6, 2017 at 3:14 AM, Rich Fromm <
rich....@gmail.com> wrote:
> On Wednesday, April 5, 2017 at 10:58:37 AM UTC-7, Naoki INADA wrote:
>>
>>
>> On Thursday, April 6, 2017 at 12:17:19 AM UTC+9, David Multer wrote:
>> > This is not a configuration issue
>>
>> Why did you think so, even when it only happens rarely?
>
>
>> > This close() issue is real in PyMySQL
>>
>> Yes. And this is error handling issue. The error will be caused by
>> configuration.
>
>
> For me it's not rare. It's happening on every write. (Admittedly, testing
> has been very limited, but that's partly b/c I can't write to the DB.)
>
> Do you have any thoughts about what kind of configuration might cause this?
> To be clear I do get the error when the backend is AWS/RDS/Aurora. I do not
> get the error when the backend is a mysql:5.7 docker container. This is my
> first time using RDS, so I suppose there might be something misconfigured,
> but I don't know what that might be.
There are may way to break it, and very limited way to configure properly.
In other words, I don't know what's your case.
But very common mistakes are:
* Using multithreading, wihtout knowing how it works.
* easy way to fix: using only process worker. don't create any
connection before forking.
* Using connection pooling without house keeping (closing connection when idle).
* easy way to fix: Closing pool at the end of each request.
Connections can be reused
while processing one HTTP request, but it won't reused among may requests.
It's efficient enough for most cases
Connection pooling is hard to configure right way.
Long living connection is root of evil.
See also:
https://github.com/go-sql-driver/mysql/issues/529#issuecomment-290032952
I've tired to describe it again and again.
Writing English is much harder to me than writing Python or Go....
>
> Regarding client configuration, my code is abstracted way higher than the
> actual db writes. I'm using SQLAlchemy 1.1.5 and Flask-SQLAlchemy 2.1. I
> have not tried to recreate the issue with lower level operations.
>
In SQLAlchemy, you can close pool by:
session.get_bind().dispose()
You can call it from gunicorn:
http://docs.gunicorn.org/en/latest/settings.html#post-request
I read manual of SQLAlchemy and guncorn for you, while I'm not free
tech support.
I don't want to pay my time and energy for this type of question.
It leads me to burn-out. I hope some volunteer reply to this type of
question...
(see also:
https://medium.com/@methane/why-you-must-not-ask-questions-on-github-issues-51d741d83fde)