Fix issue 778:  OperationalError: (OperationalError) server closed the connection unexpectedly

Yes, it is in a 'while True' statement, and it will call f() several times which is specified by 'retry_times' until f() succeeds.