-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support in Pool retry to run again the query if the database is restarted #290
Comments
Yes, I'm planning to do this, however, I'm not sure what the best API choice would be:
Any insight on how this feels better? /cc @simolus3 |
I think the ideal would be to have this option in PoolSettings it seems that in Java BaseObjectPoolConfig has a retry option "In this particular case the PostgreSQL connection is telling you that the server was shut down after the connection was created. DBCP connection pool does not handle this condition with it's default configuration. It seems that in C# SQL Server also has a retry option https://learn.microsoft.com/en-us/sql/connect/ado-net/configurable-retry-logic-sqlclient-introduction?view=sql-server-ver16 At the moment I'm doing something like this, a workaroundimport 'package:eloquent/eloquent.dart';
import 'package:rava_backend/rava_backend.dart';
import 'package:shelf/shelf.dart';
import 'package:postgres/postgres.dart' as postgres;
final auditoriaService = AuditoriaService();
class AuditoriaService {
late Connection conn;
late AuditoriaRepository repo;
int _retryCount = 0;
final int _retryLimit = 10;
AuditoriaService();
Future<void> init() async {
conn = await DBLayer().connect('auditoria');
repo = AuditoriaRepository(conn);
_retryCount = 0;
}
Future<void> acaoInserir(String objeto, Request req) async {
await _insert(Auditoria.acaoInserir(
usuario: req.token?.loginName ?? '', objeto: objeto));
}
Future<void> acaoAtualizar(String objeto, Request req) async {
await _insert(Auditoria.acaoAtualizar(
usuario: req.token?.loginName ?? '', objeto: objeto));
}
Future<void> acaoRemover(String objeto, Request req) async {
await _insert(Auditoria.acaoRemover(
usuario: req.token?.loginName ?? '', objeto: objeto));
}
Future<void> _insert(Auditoria auditoria) async {
try {
await repo.insert(auditoria);
} catch (e) {
if (e is postgres.PgException &&
e.toString().contains('connection is not open') &&
_retryCount < _retryLimit) {
await init();
_retryCount++;
print('restart');
await repo.insert(auditoria);
} else {
rethrow;
}
}
}
}
|
Given that this is likely pool-specific, putting it on |
I've reviewed my prior use of
https://pub.dev/documentation/postgres_pool/latest/postgres_pool/PgPool/runTx.html It is usually specific to the kind of processing I want to do, and more strangely, it specifically did not retry on network errors - which now looks strange, but the processes are restarted via an external I think the Also to consider: we have |
Iterating a bit more on this: we may split the connection-related retries (which in the pool context may just land on a different instance) and the application-logic retries (which may be run on the same instance).
|
Hi, is there any example of a Pool usage available? |
What are you looking for? It is mostly a drop-in for connections and their renewals, so there is not much to it in terms of how to use them. Maybe the tests can give you further hints? |
I reformulated the question here |
Just to mention, there is an "unreferenced"
(I don't have any ideas to contribute on what the API could be, except that implementing exponential backoff would be nice.) |
@ryanheise Yes, that's something I wanted to include in the |
It would be very useful to have a retry if the query throws an error if the database is restarted
The text was updated successfully, but these errors were encountered: