]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Allow for expected behaviour of synchronous SQL drivers
authorNick Porter <nick@portercomputing.co.uk>
Fri, 6 Sep 2024 12:36:42 +0000 (13:36 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 17 Sep 2024 11:15:19 +0000 (12:15 +0100)
src/modules/rlm_sql/sql.c

index 15239ca8c48308f538afda8fee38ff343e03c09f..9a2fb49b1bca96d15a9a256c5052b625cdccde4c 100644 (file)
@@ -595,7 +595,21 @@ unlang_action_t rlm_sql_trunk_query(rlm_rcode_t *p_result, UNUSED int *priority,
        switch (status) {
        case TRUNK_ENQUEUE_OK:
        case TRUNK_ENQUEUE_IN_BACKLOG:
-               if (unlang_function_push(request, sql_trunk_query_start,
+               /*
+                *      Drivers such as SQLite which are synchronous run the query immediately
+                *      on queueing.  If the query fails then the trunk request will be failed
+                *      in which case the query_ctx will no longer have a trunk request.
+                */
+               if (!query_ctx->treq) RETURN_MODULE_FAIL;
+
+               /*
+                *      Synchronous drivers will have processed the query and set the
+                *      state of the trunk request to reapable - so in that case don't
+                *      yield (in sql_trunk_query_start)
+                */
+               if (unlang_function_push(request,
+                                        query_ctx->treq->state == TRUNK_REQUEST_STATE_REAPABLE ?
+                                               NULL : sql_trunk_query_start,
                                         query_ctx->type == SQL_QUERY_SELECT ?
                                                query_ctx->inst->driver->sql_select_query_resume :
                                                query_ctx->inst->driver->sql_query_resume,