Index: channels/chan_dahdi.c =================================================================== --- channels/chan_dahdi.c (revision 163827) +++ channels/chan_dahdi.c (working copy) @@ -3735,15 +3735,26 @@ if (strcmp(ast->exten, "fax")) { const char *target_context = S_OR(ast->macrocontext, ast->context); + /* We need to unlock 'ast' here because ast_exists_extension has the + * potential to start autoservice on the channel. Such action is prone + * to deadlock. + */ + ast_mutex_unlock(&p->lock); + ast_channel_unlock(ast); if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) { + ast_channel_lock(ast); + ast_mutex_lock(&p->lock); if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Redirecting %s to fax extension\n", ast->name); /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */ pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten); if (ast_async_goto(ast, target_context, "fax", 1)) ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context); - } else + } else { + ast_channel_lock(ast); + ast_mutex_lock(&p->lock); ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n"); + } } else if (option_debug) ast_log(LOG_DEBUG, "Already in a fax extension, not redirecting\n"); } else if (option_debug)