session: fix race condition in fifo allocation 15/32115/5
authorliuyacan <liuyacan@corp.netease.com>
Sun, 25 Apr 2021 12:11:30 +0000 (20:11 +0800)
committerFlorin Coras <florin.coras@gmail.com>
Mon, 26 Apr 2021 04:25:40 +0000 (04:25 +0000)
Under some timing conditions,VCL may receive CONNECTED/ACCEPTED
event before ADD_SEGMENT event.

Timing example:

2 threads call segment_manager_alloc_session_fifos() parallelly

         Thread 1                Thread 2

       sm read lock                 |
            |                       |
     try to alloc fifo =>failed     |
            |                       |
       sm read unlock               |
            |                       |
       sm write lock                |
            |                       |
       add segment                  |
            |                       |
       sm write unlock              |
            |                  sm read lock
            |                       |
            |               try to alloc fifo=>successful
       sm read lock                 |
            |                  sm read unlock
            |                       |
            |                 emit CONNECTED/ACCEPTED
   emit ADD_SEGMENT event
            |
       sm read unlock

This commit move ADD_SEGMENT notification under the protection
of the write lock in some scenarios.

Type: fix

Signed-off-by: liuyacan <liuyacan@corp.netease.com>
Change-Id: I25d5475c5e6d37cfccefa9506f6030c26ce8ee9b


No differences found