[Asterisk-code-review] chan_console: Fix deadlock when reading audio. (asterisk[master])

N A asteriskteam at digium.com
Thu Apr 6 19:17:52 CDT 2023


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/20036 )


Change subject: chan_console: Fix deadlock when reading audio.
......................................................................

chan_console: Fix deadlock when reading audio.

When calling a console channel, chan_console will
deadlock due to the console pivot lock being held
persistently. This is due to holding it locked during
Pa_ReadStream, which is a blocking call.

This adjusts the locking order to resolve the deadlock
and allow console channels to function normally.

Reported-by: Sebastian Gutierrez

ASTERISK-30481 #close

Change-Id: I2d936bdcd4bcf18ce2aeb3b7bdb5cd3589a6d6d8
---
M channels/chan_console.c
1 file changed, 25 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/36/20036/1

diff --git a/channels/chan_console.c b/channels/chan_console.c
index 5189212..97be8c1 100644
--- a/channels/chan_console.c
+++ b/channels/chan_console.c
@@ -276,15 +276,17 @@
 
 	for (;;) {
 		pthread_testcancel();
-		console_pvt_lock(pvt);
 		res = Pa_ReadStream(pvt->stream, buf, sizeof(buf) / sizeof(int16_t));
-		console_pvt_unlock(pvt);
 		pthread_testcancel();
 
+		console_pvt_lock(pvt);
 		if (!pvt->owner) {
+			console_pvt_unlock(pvt);
 			return NULL;
 		}
 
+		console_pvt_unlock(pvt);
+
 		if (res == paNoError)
 			ast_queue_frame(pvt->owner, &f);
 	}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/20036
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I2d936bdcd4bcf18ce2aeb3b7bdb5cd3589a6d6d8
Gerrit-Change-Number: 20036
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230407/ac5c2c25/attachment-0001.html>


More information about the asterisk-code-review mailing list