[aio] host_monitoring_v2 without a topology plugin fails the first statement on cluster-endpoint connections
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 49/100
Direção de pesquisa
Start with aio/wrapper.py and _build_host_list_provider, then compare the Aurora dialect provider selection in database_dialect.py with the async behavior. Trace how AsyncHostMonitoringPlugin._get_monitoring_host_info identifies and caches a host, using the described mocked reproduction as a starting point. Done when the first statement succeeds through a cluster endpoint and monitoring targets the connected instance, with regression coverage for the failure and cache behavior.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Describe the bug
With the async API, host_monitoring_v2 used without a topology plugin (no failover, failover_v2, aurora_connection_tracker, ...) fails the first statement on every new connection made through an Aurora cluster endpoint, with AwsWrapperError: [HostMonitoringV2Plugin] Unable to identify the connected database instance. Later statements on that connection succeed, but the monitor watches the cluster endpoint's DNS name instead of the instance the connection is on.
Cause:
aio/wrapper.py_build_host_list_providerreturnsAsyncStaticHostListProviderwhenpluginscontains none of_TOPOLOGY_REQUIRING_PLUGINS, whatever the database dialect.host_monitoring_v2isn't in that set.- For a cluster endpoint,
AsyncHostMonitoringPlugin._get_monitoring_host_infocallsplugin_service.identify_connection. With the static provider the topology has nohost_id, so it returnsNoneand the plugin raises before running the statement. _get_monitoring_host_infoassignsself._monitoring_host_info = current_host_infobefore identifying, so on the next statement it returns the cached cluster endpoint and monitors that.
The sync wrapper doesn't hit this: Aurora dialects always use RdsHostListProvider (database_dialect.py, AuroraPgDialect.get_host_list_provider_supplier), regardless of plugins, so identify_connection resolves the instance.
Expected Behavior
As in sync, host_monitoring_v2 alone on a cluster endpoint identifies the instance the connection landed on and monitors it, and the first statement runs normally.
What plugins are used? What other connection properties were set?
wrapper_dialect=aurora-pg&wrapper_plugins=host_monitoring_v2, connecting through the cluster (writer) endpoint. With failover added, or through an instance endpoint, it works.
Current Behavior
Checked without a database by building the provider the way connect does and calling _get_monitoring_host_info with get_instance_id patched to return an instance id:
AsyncStaticHostListProvider mydb.cluster-xyz... -> 1st call: AwsWrapperError: Unable to identify the connected database instance
2nd call: monitors mydb.cluster-xyz.us-east-1.rds.amazonaws.com
AsyncStaticHostListProvider inst-1.xyz... -> monitors inst-1.xyz.us-east-1.rds.amazonaws.com
Reproduction Steps
import asyncio
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
from aws_advanced_python_wrapper.aio import release_resources_async
async def main():
engine = create_async_engine(
"postgresql+aws_wrapper_psycopg://USER:PASSWORD@<name>.cluster-<id>.<region>.rds.amazonaws.com:5432/DB"
"?wrapper_dialect=aurora-pg&wrapper_plugins=host_monitoring_v2")
try:
async with engine.connect() as conn:
await conn.execute(text("SELECT 1")) # raises AwsWrapperError
finally:
await engine.dispose()
await release_resources_async()
asyncio.run(main())
Possible Solution
Match sync: pick the topology-aware provider from the Aurora/Multi-AZ/Global dialect even when no topology plugin is configured, or add host_monitoring_v2 (and host_monitoring) to _TOPOLOGY_REQUIRING_PLUGINS. Either way, resolve the instance (the topology monitor is shared per cluster after #1285, so this costs one monitoring connection per cluster). Separately, _get_monitoring_host_info shouldn't cache the cluster endpoint when identification fails.
Additional Information/Context
Found while answering a user question about using host_monitoring_v2 without failover. Related: #1284.
The AWS Advanced Python Wrapper version used
main at 8feea85 (3.1.0)
python version used
Python 3.14
Operating System and version
macOS (checked locally, not against a live cluster)
- Linguagem predominante
- Python
- Estrelas
- 99
- Forks
- 24
- Merge médio
- 1d 7h
- PRs com merge (30d)
- 4
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de aws/aws-advanced-python-wrapper
-
[aio] host_monitoring_v2: event loops stop each other's monitors, recreating them on every statementTalvez já em andamento @AhmadMasry assumiu há 20 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
aws/aws-advanced-python-wrapper#1287 ·
Mantenedores costumam responder em até 1 dia
-
Async: every connection opens its own topology monitor connection (pool of N holds 2N connections)Talvez já em andamento @AhmadMasry assumiu há 20 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
aws/aws-advanced-python-wrapper#1284 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
socket_timeout includes queueing time in a shared, unconfigurable, process-wide thread pool, causing misleading QueryTimeoutErrors on unrelated queriesTalvez já em andamento @hippi345 assumiu há 9 dias. Abertabug
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
aws/aws-advanced-python-wrapper#1278 ·
Mantenedores costumam responder em até 1 dia
-
[aio] aurora_connection_tracker closes its own connection on the first statement of every cluster-endpoint connectionTalvez já em andamento @AhmadMasry assumiu há 20 dias. Abertabug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 72/100
aws/aws-advanced-python-wrapper#1276 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
aws/aws-advanced-python-wrapper#1275 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de aws/aws-advanced-python-wrapper
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
UKGovernmentBEIS/optstop#10 ·
-
maintenance
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
pollen-robotics/reachy_mini#1508 ·
Mantenedores costumam responder em até 1 dia
-
[BUG] `cloud-keys.env` values retain enclosing quotes causing 401 Unauthorized, and missing utf-8 encoding crashes on WindowsTalvez já em andamento @divyanshu07-code assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
open-jarvis/OpenJarvis#1192 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
sylvainmetayer/homelab#851 ·
Mantenedores costumam responder em até 1 dia