Review Board 1.7.16


Stasis: address refcount races; implementation comments

Review Request #2746 - Created Aug. 7, 2013 and submitted

David Lee
/trunk
ASTERISK-22243
Reviewers
asterisk-dev
mjordan
Asterisk
Change r395954 reordered some stasis object destruction, which should
have been fine. Unfortunately, it caused some hard to reproduce issues
related to objects being accessed after they had been destroyed. The
patch in r396329 fixed the destruction order problem; this patch
addresses the underlying issue. A few other stasis-related fixes were
also added.

 * Add ref-bumps around areas where objects may get transitively
   destroyed. (For example, where we lock a topic, unref a subscription,
   which unrefs the topic, which explodes the topic when we try to
   unlock it.)

 * Wrote an extensive doxygen page about Stasis implementation,
   relationships between objects, lifecycles of objects, how the
   refcounting works, etc. Many other comments were added, corrected, or
   cleaned up.

 * Added an assert to the topic dtor to catch extra ref decrements.

 * Fixed type used after destruction errors for graceful shutdown in
   stasis_channels.c.

 * I added two unit tests in an attempt to catch destruction order
   issues. Since the underlying cause is a race condition, though, the
   tests rarely failed even when the code was wrong.

 * Fixed a leak in stasis_cache_pattern.c.
Unit tests pass.

Reverted r396329, ran unit tests and scenarios that seemed to aggravate the race
condition without error.

Changes between revision 1 and 2

1 2 3
1 2 3

  1. /trunk/include/asterisk/astobj2.h: Loading...
  2. /trunk/main/stasis.c: Loading...
/trunk/include/asterisk/astobj2.h
Diff Revision 1 Diff Revision 2
[20] 508 lines
[+20] [+] void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options);
509
#define ao2_ref(o,delta)       __ao2_ref((o), (delta))
509
#define ao2_ref(o,delta)       __ao2_ref((o), (delta))
510

    
   
510

   
511
#endif
511
#endif
512

    
   
512

   
513
/*!
513
/*!

    
   
514
 * \since 12
514
 * \brief Bump refcount on an AO2 object by one, returning the object.
515
 * \brief Bump refcount on an AO2 object by one, returning the object.
515
 *
516
 *
516
 * This is useful for inlining a ref bump, and you don't care about the ref
517
 * This is useful for inlining a ref bump, and you don't care about the ref
517
 * count.
518
 * count.
518
 *
519
 *
519
 * \param obj AO2 object to bump the refcount on.
520
 * \param obj AO2 object to bump the refcount on.
520
 * \retval The given \a obj pointer.
521
 * \retval The given \a obj pointer.
521
 */
522
 */
522
#define ao2_ref1(obj)					\
523
#define ao2_refbump(obj)				\
523
	({						\
524
	({						\
524
		typeof(obj) __obj_ ## __LINE__ = (obj);	\
525
		typeof(obj) __obj_ ## __LINE__ = (obj);	\
525
		ao2_ref(__obj_ ## __LINE__, +1);	\
526
		ao2_ref(__obj_ ## __LINE__, +1);	\
526
		__obj_ ## __LINE__;			\
527
		__obj_ ## __LINE__;			\
527
	})
528
	})
[+20] [20] 1430 lines
/trunk/main/stasis.c
Diff Revision 1 Diff Revision 2
 
  1. /trunk/include/asterisk/astobj2.h: Loading...
  2. /trunk/main/stasis.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.