app_record: Fix hangup handling during beep and before record loop#1
Merged
Conversation
When a hangup occurs while app_record is playing the initial beep (or immediately after it), but before entering the main recording loop, the application does not detect the hangup and continues running until the maxduration timeout expires. This change properly handles hangup in two places: 1. After ast_waitstream() returns -1 during beep playback, indicating that the channel was hung up while the beep was playing. Also check for hangup when ast_streamfile() itself fails, as this may also be caused by a hangup condition. 2. As a safety net, check ast_check_hangup() before entering the recording loop. This covers the case where hangup arrives after the beep completes (or when using the quiet option) but before frames are read. This ensures the application exits immediately with RECORD_STATUS set to HANGUP rather than waiting for the full timeout duration. Resolves: asterisk#1790
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a hangup occurs while app_record is playing the initial beep (or immediately after it), but before entering the main recording loop, the application does not detect the hangup and continues running until the maxduration timeout expires.
Changes
This change properly handles hangup in two places:
After ast_waitstream() returns -1 during beep playback, indicating that the channel was hung up while the beep was playing. Also checks for hangup when ast_streamfile() itself fails, as this may also be caused by a hangup condition.
Safety net before the recording loop: checks ast_check_hangup() before entering the ast_waitfor() loop. This covers the case where hangup arrives after the beep completes (or when using the quiet option) but before frames are read.
This ensures the application exits immediately with RECORD_STATUS set to HANGUP rather than waiting for the full timeout duration.
Approach
This is an improved fix over PR asterisk#1790 by silverjoe. As suggested by InterLinked1 in that PR review, this version handles the failure of ast_streamfile/ast_waitstream directly at the source, rather than relying solely on an explicit hangup check. The safety-net check before the loop is retained for edge cases (e.g., the q option where no beep is played).
Testing
cherry-pick-to: 22
cherry-pick-to: 23
cherry-pick-to: 20