Async credential provider fails with "no running event loop" when credentials are refreshed during a long async operation
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start at the async credential_provider handling used by S3Store and put_async, then trace how credential refresh invokes Python while the multipart upload is running. Reproduce with the supplied example using credentials that expire during the upload; done means the provider is awaited on the operation's running event loop and the upload completes without no running event loop. The issue names no source files or tests, so first locate the provider implementation and related async tests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
An async credential_provider works for the first calls of an async operation, but when credentials expire in the middle of a long-running async operation (e.g. a multipart put_async), the refresh fails with RuntimeError: no running event loop, and the operation fails with UnauthenticatedError.
The docs say async credential providers are supported only with obstore's async APIs while an event loop is running. Here both conditions hold: put_async is awaited inside a running event loop, and the loop keeps running for the whole upload.
Reproduction
Credentials are valid for 1 second, the upload takes about 6 seconds:
import asyncio
import urllib.request
from datetime import UTC, datetime, timedelta
import obstore
from moto.server import ThreadedMotoServer
from obstore.store import S3Store
async def credential_provider():
print('credential_provider called')
return {
'access_key_id': 'test',
'secret_access_key': 'test',
'token': None,
'expires_at': datetime.now(UTC) + timedelta(seconds=1),
}
async def slow_data():
for _ in range(3):
await asyncio.sleep(2)
yield b'x' * 5 * 2**20
async def main():
server = ThreadedMotoServer(port=0, verbose=False)
server.start()
host, port = server.get_host_and_port()
endpoint = f'http://{host}:{port}'
urllib.request.urlopen(urllib.request.Request(f'{endpoint}/bucket', method='PUT'))
store = S3Store(
'bucket',
endpoint=endpoint,
region='us-east-1',
client_options={'allow_http': True},
credential_provider=credential_provider,
)
try:
await obstore.put_async(store, 'key', slow_data(), use_multipart=True, chunk_size=5 * 2**20)
finally:
server.stop()
asyncio.run(main())
Output:
credential_provider called
credential_provider called
Traceback (most recent call last):
...
obstore.exceptions.UnauthenticatedError: The operation lacked valid authentication credentials for path External AWS credential provider: RuntimeError: no running event loop
Debug source:
Unauthenticated {
path: "External AWS credential provider",
source: PyErr {
type: <class 'RuntimeError'>,
value: RuntimeError('no running event loop'),
traceback: None,
},
}
Expected
The provider is awaited on the event loop that the async operation was started from, and the upload completes.
Context
A workaround is a synchronous provider that runs the async code on the original loop with anyio.from_thread.run(..., token=anyio.lowlevel.current_token()) captured in that loop. obstore calls the provider from its own threads, so this does not deadlock.
Environment
- obstore 0.12.1
- Lingua principale
- Python
- Stelle
- 842
- Fork
- 50
- Merge medio
- 9h
- PR unite (30g)
- 13
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di developmentseed/obstore
-
fsspec: `get_file` silently writes nothing for `file://` and Windows pathsForse già presa @andyhetianjun l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 58/100
developmentseed/obstore#830 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
developmentseed/obstore#823 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
developmentseed/obstore#816 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
`put_async(Path)` opens files synchronously while holding the GILForse già presa @kylebarron l’ha presa 14 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
developmentseed/obstore#809 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 75/100
developmentseed/obstore#779 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di developmentseed/obstore
Issue simili
-
Task select patterns with uppercase letters never matchForse già presa @manobhisriram l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
app: scripts status: backlog type: housekeeping
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
netbox-community/netbox-scripts#239 ·
I maintainer di solito rispondono entro 1 giorno
-
Lambda deploys fail once the bundle grows by about 254 KBForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
developmentseed/titiler-cmr#341 ·
I maintainer di solito rispondono entro 1 giorno
-
Card tables add "..." to every value in a DataFrame column when any value is longer than 30 charactersForse già presa @omkarbandikatte l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno