MagicStack / MagicStack/asyncpg
How are Postgres server restarts handled?
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 8.1k
- Forks
- 469
- Merge moyen
- 18 min
- PR mergées (30 j)
- 4
Description
Hi guys,
We are using asyncpg in a web application.
Upon starting the web server, we do the following two things:
db = asyncpg.create_poolto create the connection pool for the application's DB connections.conn = await db.pool.acquire(); await conn.add_listener('foo', _callback)to register long-lived listeners to catch and handleNOTIFYevents from the DB.
Recently I restarted the Postgres server and noticed something interesting. First, connections to the DB using the db pool object saw no interruption and were still able to connect to the DB server despite it having a new PID (since the process had been restarted).
However, the conn the application relied on to receive async notifications from the server was dead/closed and so the application logic dependent upon receiving those notifications was not functioning. (This is how I reproduced this issue and discovered the cause to have been a PG server restart.)
- Why is the pool unaffected by restart? It makes sense the connection instance is dead since the socket is closed after restarting the server, but I'm a bit surprised the pool is not affected.
- I suppose the best strategy for checking for dead DB connections would be to simply check
conn.is_closedperiodically - or, is there some "on connection close" callback I can define to retry/reopen a connection (since obtaining new connections from the pool still works after restart)?
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner les points d’entrée asyncpg.create_pool, pool.acquire, add_listener et conn.is_closed décrits dans le rapport, ainsi que le comportement de PostgreSQL NOTIFY lors du redémarrage d’un serveur. Déterminez le comportement attendu des connexions du pool et des listeners de longue durée, puis documentez la méthode prise en charge pour détecter et récupérer les connexions de listener fermées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- postgresql, python
- Domaine
- backend, databases
- Type d'issue
- Documentation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100