Skip to content

Commit 3e86294

Browse files
InterLinked1kharwell
authored andcommitted
loader: Prevent deadlock using tab completion.
If tab completion using ast_module_helper is attempted during startup, deadlock will ensue because the CLI will attempt to lock the module list while it is already locked by the loader. This causes deadlock because when the loader tries to acquire the CLI lock, they are blocked on each other. Waiting for startup to complete is not feasible because the CLI lock is acquired while waiting, so deadlock will ensure regardless of whether or not a lock on the module list is attempted. To prevent deadlock, we immediately abort if tab completion is attempted on the module list before Asterisk is fully booted. ASTERISK-30039 #close Change-Id: Idd468906c512bb196631e366a8f597a0e2e9271d
1 parent 64a764c commit 3e86294

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

include/asterisk/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int ast_loader_unregister(int (*updater)(void));
283283
* \param type The type of action that will be performed by CLI.
284284
*
285285
* \retval A possible completion of the partial match.
286-
* \retval NULL if no matches were found.
286+
* \retval NULL if no matches were found or Asterisk is not yet fully booted.
287287
*/
288288
char *ast_module_helper(const char *line, const char *word, int pos, int state, int rpos, enum ast_module_helper_type type);
289289

main/loader.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,11 @@ char *ast_module_helper(const char *line, const char *word, int pos, int state,
13821382
return NULL;
13831383
}
13841384

1385+
/* Tab completion can't be used during startup, or CLI and loader will deadlock. */
1386+
if (!ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
1387+
return NULL;
1388+
}
1389+
13851390
if (type == AST_MODULE_HELPER_LOAD) {
13861391
module_load_helper(word);
13871392

0 commit comments

Comments
 (0)