brpc icon indicating copy to clipboard operation
brpc copied to clipboard

Restore reader_count in case of failure in rwlock_rdlock_impl

Open shanhe72101 opened this issue 4 months ago • 5 comments

What problem does this PR solve?

Issue Number: Fix #3051

Problem Summary:

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

shanhe72101 avatar Jul 31 '25 09:07 shanhe72101

LGTM

wwbmmm avatar Aug 01 '25 13:08 wwbmmm

Please add a UT.

done

shanhe72101 avatar Aug 02 '25 12:08 shanhe72101

@chenBright please review,thank you

shanhe72101 avatar Aug 07 '25 02:08 shanhe72101

@chenBright

  1. reader_sema should also be restored.
  2. The same problem exists with wlock.

In case of timeout, reader_sema will not be modified and does not require restoration. The same applies to rwlock->writer_sema. Perhaps I haven't uncovered the truth. Please point out the specific errors, thank you

shanhe72101 avatar Aug 11 '25 08:08 shanhe72101

bthread1                                                  bthread2
bthread_sem_timedwait
                                                          rwlock->reader_count->fetch_add(RWLockMaxReaders);
                                                          bthread_sem_post_n
                                                          bthread_mutex_unlock
rwlock->reader_count->fetch_add

In this case, reader_sema has been posted. Subsequently, there may be a problem where the write lock and read lock enter the critical section at the same time.

chenBright avatar Aug 13 '25 07:08 chenBright