[asterisk-commits] mmichelson: trunk r357775 - in /trunk: ./ main/channel.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 1 19:33:10 CST 2012


Author: mmichelson
Date: Thu Mar  1 19:33:06 2012
New Revision: 357775

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=357775
Log:
Fix race condition that can cause important control frames (such as a hangup) to be missed.

This takes two actions.

1. Move the reading of the alertpipe in __ast_read() to immediately before the
removal of frames from the readq. This means we won't do something silly like
read from the alertpipe, then ignore the fact that there's a frame to get from
the readq since channel's fdno is the AST_TIMING_FD.

2. When ast_settimeout() sets the rate to 0 and the timingfunc to NULL, if the
channel's fdno is the AST_TIMING_FD, then set the fdno to -1. This is because
if the rate is 0 and the timingfunc is NULL, it means that the channel's timing
fd is being invalidated, so any pending reads should not occur.

This may actually solve more issues than the referenced one below, but it's not
known at this time for sure.

(closes issue ASTERISK-19223)
reported by Frank-Michael Wittig

Review: https://reviewboard.asterisk.org/r/1779
........

Merged revisions 357761 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 357762 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/main/channel.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=357775&r1=357774&r2=357775
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Thu Mar  1 19:33:06 2012
@@ -3342,6 +3342,16 @@
 	c->timingfunc = func;
 	ast_channel_timingdata_set(c, data);
 
+	if (func == NULL && rate == 0 && ast_channel_fdno(c) == AST_TIMING_FD) {
+		/* Clearing the timing func and setting the rate to 0
+		 * means that we don't want to be reading from the timingfd
+		 * any more. Setting c->fdno to -1 means we won't have any
+		 * errant reads from the timingfd, meaning we won't potentially
+		 * miss any important frames.
+		 */
+		ast_channel_fdno_set(c, -1);
+	}
+
 	ast_channel_unlock(c);
 
 	return res;
@@ -3614,13 +3624,6 @@
 
 	prestate = ast_channel_state(chan);
 
-	/* Read and ignore anything on the alertpipe, but read only
-	   one sizeof(blah) per frame that we send from it */
-	if (ast_channel_internal_alert_read(chan) == AST_ALERT_READ_FATAL) {
-		f = &ast_null_frame;
-		goto done;
-	}
-
 	if (ast_channel_timingfd(chan) > -1 && ast_channel_fdno(chan) == AST_TIMING_FD) {
 		enum ast_timer_event res;
 
@@ -3669,6 +3672,13 @@
 		goto done;
 	} else if (ast_channel_fd_isset(chan, AST_JITTERBUFFER_FD) && ast_channel_fdno(chan) == AST_JITTERBUFFER_FD) {
 		ast_clear_flag(chan, AST_FLAG_EXCEPTION);
+	}
+
+	/* Read and ignore anything on the alertpipe, but read only
+	   one sizeof(blah) per frame that we send from it */
+	if (ast_channel_internal_alert_read(chan) == AST_ALERT_READ_FATAL) {
+		f = &ast_null_frame;
+		goto done;
 	}
 
 	/* Check for pending read queue */




More information about the asterisk-commits mailing list