set_client() keeps client ownership, so the index closes a caller-provided client
I maintainer di solito rispondono entro 5 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 70/100
Direzione di ricerca
Inizia dalla gestione della proprietà di SearchIndex e AsyncSearchIndex in set_client(), connect(), disconnect() e nell'iniezione nel costruttore. Traccia come vengono finalizzati o chiusi i client sincroni e asincroni, quindi aggiungi la copertura per l'iniezione nel costruttore, set_client() e connect() per verificare che i client forniti dal chiamante rimangano aperti, mentre i client creati internamente vengano rilasciati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
An index created with redis_url owns the client it lazily creates, so _owns_redis_client is True. The deprecated set_client() does not reset that flag, so after a caller swaps in their own client the index still believes it owns it and will close it. __init__(redis_client=...) already gets this right and marks such a client as not owned.
Before 0.25.0 this was latent, because the client finalizer never fired (see #657). Now that the finalizer works, the index closes the caller's client when it is garbage collected.
Affects both SearchIndex and AsyncSearchIndex, on 0.25.0.
Reproduction
import gc
from unittest import mock
from redisvl.index import SearchIndex
SCHEMA = {
"index": {"name": "probe", "prefix": "p", "storage_type": "hash"},
"fields": [{"name": "a", "type": "tag"}],
}
caller_client = mock.MagicMock()
index = SearchIndex.from_dict(SCHEMA, redis_url="redis://localhost:6379")
with mock.patch("redisvl.index.index.RedisConnectionFactory.validate_sync_redis"):
index.set_client(caller_client)
print("owns:", index._owns_redis_client) # True, should be False
del index
gc.collect()
print("caller client closed:", caller_client.close.called) # True, should be False
Observed on 0.25.0:
owns: True
caller client closed: True
The async path behaves the same, awaiting aclose() on the caller's client. Calling disconnect() explicitly closes it too, for the same reason.
Impact
Low severity but real. redis-py clients recover from close() and aclose() by reconnecting on next use, so the practical effect is unexpected connection churn on a client the caller still owns rather than a permanently broken client. Verified: ping() returns True after both close() and aclose() for sync and async clients.
The exposure is further limited because set_client() is deprecated.
Additional problem in the same method
The sync set_client() also abandons the client the index created for itself, without closing it. It overwrites __redis_client and (since 0.25.0) detaches that client's finalizer, so nothing ever closes it. The async set_client() does not have this problem because it awaits disconnect() before swapping.
Suggested fix
set_client() should mark the client as not owned, since a caller-provided client is by definition not the index's to close, and it should release the previously owned client first.
The deprecated async connect() needs care here: it creates its own client and then delegates to set_client(), so a naive ownership flip would leave a client the index created with nobody to close it. That path must keep ownership. Routing both through a small internal helper that takes ownership as a parameter handles this.
Worth covering with tests on all three entry points: constructor injection (already correct), set_client() (must not own), and connect() (must own).
- Lingua principale
- Python
- Stelle
- 432
- Fork
- 111
- Merge medio
- 5g 17h
- PR unite (30g)
- 16
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
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 redis/redis-vl-python
-
exists() depends on exact FT.INFO error wording; an unrecognised "missing index" message makes create() never create the index (regression from #672)Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
redis/redis-vl-python#773 ·
I maintainer di solito rispondono entro 5 giorni
-
Vector field with index_missing=True cannot be createdForse già presa @RaphaelFakhri l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
redis/redis-vl-python#770 ·
I maintainer di solito rispondono entro 5 giorni
-
Add Python 3.15 supportForse già presa @vishal-bala l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
redis/redis-vl-python#757 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 5 giorni
-
SearchIndex.drop_keys does not validate cluster hash-tag co-location (inconsistent with drop_documents)Forse già presa @Hashim1999164 l’ha presa 4 giorni fa. Apertabug good first issue index
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
redis/redis-vl-python#601 ·
I maintainer di solito rispondono entro 5 giorni
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
redis/redis-vl-python#300 ·
I maintainer di solito rispondono entro 5 giorni
Tutte le issue di redis/redis-vl-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
khuisman/mcp-gee-sweet#1166 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
lugassawan/swe-workbench#823 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
gramaziokohler/compas_timber#870 ·
-
security-scan-failure
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
semantica-agi/semantica#2089 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
autowarefoundation/autoware_carla_scenario#500 ·
I maintainer di solito rispondono entro 1 giorno