Skip to content

Commit 518c29d

Browse files
eugen-virtantrondn
authored andcommitted
MB-25700: Move devnull on the stack
This change prevents writing to devnull from multiple threads, which used to cause the thread sanitizer to warn about a race. The suppresion rule for drain_notification_channel() can now be removed. Change-Id: I54acd272efd6315abcdf61e4d0544315b0c0bbd1 Reviewed-on: http://review.couchbase.org/82762 Reviewed-by: Dave Rigby <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Trond Norbye <[email protected]>
1 parent 4749107 commit 518c29d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

daemon/thread.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#define ITEMS_PER_ALLOC 64
2525

26-
static char devnull[8192];
2726
extern std::atomic<bool> memcached_shutdown;
2827

2928
/* An item in the connection queue. */
@@ -248,7 +247,18 @@ static int number_of_pending(Connection *c, Connection *list) {
248247

249248
static void drain_notification_channel(evutil_socket_t fd)
250249
{
250+
/* Every time we want to notify a thread, we send 1 byte to its
251+
* notification pipe. When the thread wakes up, it tries to drain
252+
* it's notification channel before executing any other events.
253+
* Other threads (listener and other background threads) may notify
254+
* this thread up to 512 times since the last time we checked the
255+
* notification pipe, before we'll start draining the it again.
256+
*/
257+
251258
int nread;
259+
// Using a small size for devnull will avoid blowing up the stack
260+
char devnull[512];
261+
252262
while ((nread = recv(fd, devnull, sizeof(devnull), 0)) == (int)sizeof(devnull)) {
253263
/* empty */
254264
}

0 commit comments

Comments
 (0)