[Home]

Summary:ASTERISK-28713: res_stasis_playback: Error building JSON
Reporter:Sébastien Duthil (sduthil)Labels:patch
Date Opened:2020-01-24 16:39:13.000-0600Date Closed:2020-02-05 09:46:13.000-0600
Priority:MinorRegression?Yes
Status:Closed/CompleteComponents:Resources/res_stasis_playback
Versions:16.7.0 Frequency of
Occurrence
Occasional
Related
Issues:
Environment:Asterisk 16.7.0, Debian 10 BusterAttachments:( 0) 0001-res_stasis_playback-Prevent-media_index-from-going-o.patch
( 1) ari-playback.py
Description:Given I have a channel in Stasis (not in a Bridge)
When I answer the channel
When I try to play a non-existing sound file with a wrong scheme some:thing on the channel, like this:
{{POST http://asterisk:5039/ari/channels/1579822274.0/play?media=some%3Athing&playbackId=someid}}
When I get the playback info like this: {{GET http://asterisk:5039/ari/playbacks/someid}}
Then I sometimes get a status code 500 with the following error message:

{noformat}
[2020-01-24 17:27:52.8439] ERROR[25681][C-00000001]: res_stasis_playback.c:365 play_on_channel: Attempted to play URI 'some:thing' on channel 'PJSIP/lm4w1w87-00000000' but scheme is unsupported
[2020-01-24 17:27:52.8443] ERROR[25696]: json.c:607 ast_json_vpack: Error building JSON from '{s: s, s: s, s: s, s: s, s: s, s: s}': NULL string.
[2020-01-24 17:27:52.8458] ERROR[25696]:   Got 14 backtrace records
# 0: /usr/sbin/asterisk(ast_json_vpack+0xca) [0x511fe4]
# 1: /usr/sbin/asterisk(ast_json_pack+0x36) [0x511efe]
# 2: /usr/lib/asterisk/modules/res_stasis_playback.so(stasis_app_playback_to_json+0x14f) [0xb272361a]
# 3: /usr/lib/asterisk/modules/res_ari_playbacks.so(+0x16b7) [0xb270d6b7]
# 4: /usr/lib/asterisk/modules/res_ari_playbacks.so(+0x12cf) [0xb270d2cf]
# 5: /usr/lib/asterisk/modules/res_ari.so(ast_ari_invoke+0x736) [0xb28800f9]
# 6: /usr/lib/asterisk/modules/res_ari.so(+0x5601) [0xb2881601]
# 7: /usr/sbin/asterisk(+0x210ded) [0x618ded]
# 8: /usr/sbin/asterisk(+0x211f38) [0x619f38]
# 9: /usr/sbin/asterisk(+0x212287) [0x61a287]
#10: /usr/sbin/asterisk(+0x1b906d) [0x5c106d]
#11: /usr/sbin/asterisk(+0x1ca9cc) [0x5d29cc]
#12: /lib/i386-linux-gnu/libpthread.so.0(+0x6fd2) [0xb759efd2]
#13: /lib/i386-linux-gnu/libc.so.6(clone+0x66) [0xb71de6d6]
{noformat}

Expected: I get a status code 200 or 404

Reproduction: This issue only happens occasionnally. Attached is a small Python script that tries many times to reproduce the issue. I can reproduce 9/10 times with this script.

Technical investigation: Debug logs do not give any more useful information. When reproducing, in {{res_stasis_playback}}, in the function {{stasis_app_playback_to_json}}, I have the following values :

{noformat}
playback->id == someid
playback->media == some:thing
AST_VECTOR_GET(&playback->medias, playback->media_index + 1) == (null)
playback->target == channel:1579822274.0
playback->language == en
state_to_string(playback->state) == playing
playback->media_index == 1
AST_VECTOR_SIZE(&playback->medias) - 1 == 0
{noformat}

The {{media_index > AST_VECTOR_SIZE(&playback->medias) - 1}} seems to be the cause of the wrong branch condition causing the JSON to be packed with a NULL string.
Comments:By: Asterisk Team (asteriskteam) 2020-01-24 16:39:14.165-0600

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

Please note that once your issue enters an open state it has been accepted. As Asterisk is an open source project there is no guarantee or timeframe on when your issue will be looked into. If you need expedient resolution you will need to find and pay a suitable developer. Asking for an update on your issue will not yield any progress on it and will not result in a response. All updates are posted to the issue when they occur.

By: Sébastien Duthil (sduthil) 2020-01-24 16:41:21.336-0600

Here is a reproduction script using ari-py. The script requires a channel inside a Stasis application. It will then repeatedly play a non-existing sound file on the channel.

By: Sean Bright (seanbright) 2020-01-28 13:28:15.575-0600

[~sduthil], can you see if the [attached patch|^0001-res_stasis_playback-Prevent-media_index-from-going-o.patch] fixes the problem for you?

By: Sébastien Duthil (sduthil) 2020-01-30 16:39:39.322-0600

Hi Sean,

I can confirm that the patch fixes the problem for me. Without the patch, I could reproduce 9/10 times. With your patch, I reproduced 0/10 times.

Thank you!

By: Friendly Automation (friendly-automation) 2020-02-05 09:46:14.121-0600

Change 13721 merged by Friendly Automation:
res_stasis_playback: Prevent media_index from going out of bounds

[https://gerrit.asterisk.org/c/asterisk/+/13721|https://gerrit.asterisk.org/c/asterisk/+/13721]

By: Friendly Automation (friendly-automation) 2020-02-05 09:49:10.007-0600

Change 13708 merged by Friendly Automation:
res_stasis_playback: Prevent media_index from going out of bounds

[https://gerrit.asterisk.org/c/asterisk/+/13708|https://gerrit.asterisk.org/c/asterisk/+/13708]

By: Friendly Automation (friendly-automation) 2020-02-05 10:40:29.873-0600

Change 13709 merged by Friendly Automation:
res_stasis_playback: Prevent media_index from going out of bounds

[https://gerrit.asterisk.org/c/asterisk/+/13709|https://gerrit.asterisk.org/c/asterisk/+/13709]