Skip to content

Commit 95e6d46

Browse files
committed
cache xlat can succeed if it returns no data.
i.e. "no data in cache" isn't an xlat failure, it's an xlat success with no data.
1 parent 6025492 commit 95e6d46

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/modules/rlm_cache/rlm_cache.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,11 @@ xlat_action_t cache_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
937937
case RLM_MODULE_OK: /* found */
938938
break;
939939

940+
case RLM_MODULE_NOTFOUND: /* !found is "no data" */
941+
talloc_free(target);
942+
cache_release(inst, request, &handle);
943+
return XLAT_ACTION_DONE;
944+
940945
default:
941946
talloc_free(target);
942947
cache_release(inst, request, &handle);
@@ -966,9 +971,9 @@ xlat_action_t cache_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
966971
cache_release(inst, request, &handle);
967972

968973
/*
969-
* Check if we found a matching map
974+
* If we found a value, then the output has been updated.
975+
* Otherwise, there is no output. Either way, the xlat succeeded.
970976
*/
971-
if (!map) return XLAT_ACTION_FAIL;
972977

973978
return XLAT_ACTION_DONE;
974979
}

src/tests/modules/cache_rbtree/cache-xlat.unlang

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,31 @@ if (Login-LAT-Node) {
2929
# Regression test for deadlock on notfound
3030
Filter-Id := 'testkey0'
3131

32+
#
33+
# There is no request.Login-LAT-Port, so the input is empty.
34+
#
3235
Login-LAT-Node := %cache(request.Login-LAT-Port)
3336

3437
# Would previously deadlock
3538
Login-LAT-Port := %cache(request.Login-LAT-Port)
3639

40+
#
41+
# Get the value for a key which doesn't exist. The xlat should succeed, but return no data.
42+
#
43+
Filter-Id := 'nosuchkey'
44+
request.Login-LAT-Service := %cache('request.Callback-Id')
45+
if request.Login-LAT-Service {
46+
test_fail
47+
}
48+
49+
#
50+
# And then verify that the previous cache entry hasn't been deleted
51+
#
52+
Filter-Id := 'testkey'
53+
request.Login-LAT-Service := %cache('request.Callback-Id')
54+
55+
if (Login-LAT-Service != control.Callback-Id) {
56+
test_fail
57+
}
58+
3759
test_pass

0 commit comments

Comments
 (0)