From: Nick Porter Date: Fri, 6 Sep 2024 12:36:42 +0000 (+0100) Subject: Allow for expected behaviour of synchronous SQL drivers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6deae18036fdbd4f79d32a3d1cc22f93233c0b31;p=thirdparty%2Ffreeradius-server.git Allow for expected behaviour of synchronous SQL drivers --- diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 15239ca8c48..9a2fb49b1bc 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -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,