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.
/trunk/include/asterisk/astobj2.h
Revision 396357 New Change
[20] 507 lines
[+20] [+] void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options);
508
#define ao2_t_ref(o,delta,tag) __ao2_ref((o), (delta))
508
#define ao2_t_ref(o,delta,tag) __ao2_ref((o), (delta))
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
/*!

    
   
514
 * \since 12

    
   
515
 * \brief Bump refcount on an AO2 object by one, returning the object.

    
   
516
 *

    
   
517
 * This is useful for inlining a ref bump, and you don't care about the ref

    
   
518
 * count. Also \c NULL safe, for even more convenience.

    
   
519
 *

    
   
520
 * \param obj AO2 object to bump the refcount on.

    
   
521
 * \retval The given \a obj pointer.

    
   
522
 */

    
   
523
#define ao2_bump(obj)						\

    
   
524
	({							\

    
   
525
		typeof(obj) __obj_ ## __LINE__ = (obj);		\

    
   
526
		if (__obj_ ## __LINE__) {			\

    
   
527
			ao2_ref(__obj_ ## __LINE__, +1);	\

    
   
528
		}						\

    
   
529
		__obj_ ## __LINE__;				\

    
   
530
	})

    
   
531

   
513
int __ao2_ref_debug(void *o, int delta, const char *tag, const char *file, int line, const char *func);
532
int __ao2_ref_debug(void *o, int delta, const char *tag, const char *file, int line, const char *func);
514
int __ao2_ref(void *o, int delta);
533
int __ao2_ref(void *o, int delta);
515

    
   
534

   
516
/*! @} */
535
/*! @} */
517

    
   
536

   
[+20] [20] 1424 lines
/trunk/main/stasis.c
Revision 396357 New Change
 
/trunk/main/stasis_cache.c
Revision 396357 New Change
 
/trunk/main/stasis_cache_pattern.c
Revision 396357 New Change
 
/trunk/main/stasis_channels.c
Revision 396357 New Change
 
/trunk/tests/test_stasis.c
Revision 396357 New Change
 
  1. /trunk/include/asterisk/astobj2.h: Loading...
  2. /trunk/main/stasis.c: Loading...
  3. /trunk/main/stasis_cache.c: Loading...
  4. /trunk/main/stasis_cache_pattern.c: Loading...
  5. /trunk/main/stasis_channels.c: Loading...
  6. /trunk/tests/test_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.