Commit a9a4c3e
committed
MB-35993: Add synchronization to auditHandle
The audit daemon handle (auditHandle) does not have any
synchronization around it, resulting in TSan warnings during shutdown
as the Audit object may have been deleted:
ThreadSanitizer: data race
Write of size 8 at 0x0000009b0130 by main thread:
#0 std::swap(cb::audit::Audit*&, cb::audit::Audit*&) /usr/local/include/c++/7.3.0/bits/move.h:199 (memcached+0x0000004f335a)
#1 std::unique_ptr >::reset(cb::audit::Audit*) /usr/local/include/c++/7.3.0/bits/unique_ptr.h:374 (memcached+0x0000004f335a)
#2 shutdown_audit() kv_engine/daemon/mcaudit.cc:348 (memcached+0x0000004f335a)
#3 memcached_main kv_engine/daemon/memcached.cc:2503 (memcached+0x000000435a46)
#4 main kv_engine/daemon/main.cc:33 (memcached+0x00000042145e)
Previous read of size 8 at 0x0000009b0130 by thread T8 (mutexes: write M1049192993527234104):
#0 std::__uniq_ptr_impl >::_M_ptr() const /usr/local/include/c++/7.3.0/bits/unique_ptr.h:147 (memcached+0x0000004f3433)
#1 std::unique_ptr >::get() const /usr/local/include/c++/7.3.0/bits/unique_ptr.h:337 (memcached+0x0000004f3433)
#2 std::unique_ptr >::operator->() const /usr/local/include/c++/7.3.0/bits/unique_ptr.h:331 (memcached+0x0000004f3433)
#3 stats_audit(std::function)> const&, Cookie&) kv_engine/daemon/mcaudit.cc:361 (memcached+0x0000004f3433)
#4 stat_audit_executor kv_engine/daemon/protocol/mcbp/stats_context.cc:446 (memcached+0x000000528f72)
Location is global 'auditHandle' of size 8 at 0x0000009b0130 (memcached+0x0000009b0130)
Fix by using folly::Synchronized<> for the auditHandle. Note that
exclusive access is only needed during initialization & shutdown, so
there should be no additional contention for actually adding audit
events (where shared access is sufficient).
Change-Id: I34966f08674c6363fde4592b5c4bede48747fb2f
Reviewed-on: http://review.couchbase.org/114945
Tested-by: Build Bot <[email protected]>
Reviewed-by: Richard de Mellow <[email protected]>
Reviewed-by: Trond Norbye <[email protected]>1 parent 3c221fd commit a9a4c3e
1 file changed
+36
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | | - | |
117 | | - | |
118 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
263 | 268 | | |
264 | 269 | | |
265 | 270 | | |
266 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
267 | 277 | | |
268 | 278 | | |
269 | 279 | | |
| |||
335 | 345 | | |
336 | 346 | | |
337 | 347 | | |
338 | | - | |
| 348 | + | |
339 | 349 | | |
340 | | - | |
| 350 | + | |
341 | 351 | | |
342 | 352 | | |
343 | | - | |
344 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
345 | 356 | | |
346 | 357 | | |
347 | 358 | | |
348 | | - | |
| 359 | + | |
349 | 360 | | |
350 | 361 | | |
351 | 362 | | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
358 | 373 | | |
359 | 374 | | |
360 | 375 | | |
361 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
362 | 381 | | |
0 commit comments