Metaswitch/sprout — pull request #21 by mike-evans (2013-05-20 12:46:08+00:00)
Title: [Reviewer Matt] Change ConnectionPool::create_connection to use pjsip_tpmgr_acquire_tran...

This is a fix to issue 11, which was a race condition between creating a TCP connection, the connection failing more-or-less immediately, and ConnectionPool::create_connection trying to increment the reference count. The fix is to use the PJSIP pjsip_tpmgr_acquire_transport API to create the TCP connection, rather than calling the TP factory directly (which, with hindsight was a bad idea on my part). pjsip_tpmgr_acquire_transport increments the reference count on the transport itself, and holds a lock while doing this to close the race condition.

I've tested this by running the Sprout unit tests and some live testing. I haven't run stress tests to provoke the particularly scenario.