From 3e2649f1f1e7aad329493657b79ea9e93a1437fb Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 26 Mar 2025 22:46:00 +0100 Subject: [PATCH] hnsw_insert() should never fail in practice. We pass our aborting allocation function to the HNSW lib, the only other reason for it to fail is pthread mutex locking failing but this is also practically impossible AFAIK in modern systems, and if it happens (for kernel reosurces shortage) anyway to abort is the best thing to do: otherwise we would have to return that we could not complete the operation for some reason, which is not uniform with everything Redis does. In Redis under normal conditions writes must succeed if they are semantically correct, or the server crash for OOM. --- vset.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vset.c b/vset.c index 0f160de51e..1bf2120fa8 100644 --- a/vset.c +++ b/vset.c @@ -192,6 +192,7 @@ int vectorSetInsert(struct vsetObject *o, float *vec, int8_t *qvec, float qrange * the old value. */ hnsw_delete_node(o->hnsw, node, NULL); node = hnsw_insert(o->hnsw,vec,qvec,qrange,0,nv,ef); + RedisModule_Assert(node != NULL); RedisModule_DictReplace(o->dict,val,node); /* If attrib != NULL, the user wants that in case of an update we @@ -392,6 +393,7 @@ int VADD_CASReply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { (newnode = hnsw_try_commit_insert(vset->hnsw, ic)) == NULL) { newnode = hnsw_insert(vset->hnsw, vec, NULL, 0, 0, nv, ef); + RedisModule_Assert(newnode != NULL); } else { newnode->value = nv; }