{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/osquery/pulls/comments/89665418","pull_request_review_id":10209684,"id":89665418,"diff_hunk":"@@ -114,6 +120,41 @@ class RocksDBDatabasePlugin : public DatabasePlugin {\n /// Backing-storage provider for osquery internal/core.\n REGISTER_INTERNAL(RocksDBDatabasePlugin, \"database\", \"rocksdb\");\n \n+class RocksDBGuard {\n+ public:\n+  RocksDBGuard() : my_tid_(platformGetTid()), locked_(false) {}\n+\n+  bool safeEnter() {\n+    if (!owner_tid_is_valid_ || owner_tid_ != my_tid_) {\n+      mu_.lock();\n+      owner_tid_ = my_tid_;\n+      owner_tid_is_valid_ = true;\n+      locked_ = true;\n+    }\n+    return locked_;\n+  }\n+\n+  ~RocksDBGuard() {\n+    if (locked_) {\n+      owner_tid_is_valid_ = false;\n+      mu_.unlock();\n+    }\n+  }\n+\n+ private:\n+  int my_tid_;\n+  bool locked_;\n+\n+  static std::mutex mu_;\n+  static int owner_tid_;\n+  // linux has no notion of an invalid thread id, hence owner_tid_is_valid_\n+  static bool owner_tid_is_valid_;","path":"osquery/database/plugins/rocksdb.cpp","position":57,"original_position":57,"commit_id":"1c6fa2b29c1776f8b1ca2586ba448a8a73f6ca86","original_commit_id":"1c6fa2b29c1776f8b1ca2586ba448a8a73f6ca86","user":{"login":"theopolis","id":981645,"avatar_url":"https://avatars.githubusercontent.com/u/981645?v=3","gravatar_id":"","url":"https://api.github.com/users/theopolis","html_url":"https://github.com/theopolis","followers_url":"https://api.github.com/users/theopolis/followers","following_url":"https://api.github.com/users/theopolis/following{/other_user}","gists_url":"https://api.github.com/users/theopolis/gists{/gist_id}","starred_url":"https://api.github.com/users/theopolis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theopolis/subscriptions","organizations_url":"https://api.github.com/users/theopolis/orgs","repos_url":"https://api.github.com/users/theopolis/repos","events_url":"https://api.github.com/users/theopolis/events{/privacy}","received_events_url":"https://api.github.com/users/theopolis/received_events","type":"User","site_admin":false},"body":"The owner thread ID is invalid until the owner is the executing thread ID?","created_at":"2016-11-26T04:37:43Z","updated_at":"2016-11-26T04:37:43Z","html_url":"https://github.com/facebook/osquery/pull/2749#discussion_r89665418","pull_request_url":"https://api.github.com/repos/facebook/osquery/pulls/2749","_links":{"self":{"href":"https://api.github.com/repos/facebook/osquery/pulls/comments/89665418"},"html":{"href":"https://github.com/facebook/osquery/pull/2749#discussion_r89665418"},"pull_request":{"href":"https://api.github.com/repos/facebook/osquery/pulls/2749"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/osquery/pulls/2749","id":93508021,"html_url":"https://github.com/facebook/osquery/pull/2749","diff_url":"https://github.com/facebook/osquery/pull/2749.diff","patch_url":"https://github.com/facebook/osquery/pull/2749.patch","issue_url":"https://api.github.com/repos/facebook/osquery/issues/2749","number":2749,"state":"open","locked":false,"title":"Fix Deadlock in rocksdb log callback","user":{"login":"lambda-conjecture","id":22373129,"avatar_url":"https://avatars.githubusercontent.com/u/22373129?v=3","gravatar_id":"","url":"https://api.github.com/users/lambda-conjecture","html_url":"https://github.com/lambda-conjecture","followers_url":"https://api.github.com/users/lambda-conjecture/followers","following_url":"https://api.github.com/users/lambda-conjecture/following{/other_user}","gists_url":"https://api.github.com/users/lambda-conjecture/gists{/gist_id}","starred_url":"https://api.github.com/users/lambda-conjecture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lambda-conjecture/subscriptions","organizations_url":"https://api.github.com/users/lambda-conjecture/orgs","repos_url":"https://api.github.com/users/lambda-conjecture/repos","events_url":"https://api.github.com/users/lambda-conjecture/events{/privacy}","received_events_url":"https://api.github.com/users/lambda-conjecture/received_events","type":"User","site_admin":false},"body":"This fix resolves a deadlock condition as follows:\r\n\r\nThread calls a put operation in rocksdb\r\nrocksdb acquires a mutex, mu_, in its write path.\r\nrocksdb decides to flush, which has a LOG call in its path.\r\nThe LOG call calls GlogRocksDBLogger::Logv, which calls Google Log\r\nGoogle Log decides to flush, which ends up making a call back to rocksdb put\r\n\r\nThe thread deadlocks on itself, since rocksdb's mutex is a fast (ie., non-recursive) mutex.\r\n\r\nThe recommended \"thread safe\" way for google logging is to use RAW_LOG_XXX method, which is what this PR does.\r\n\r\nUnfortunately, the side effect of this is that rocksdb logs will not be sent to a TLS backend or to a File Logger. They will merely show up on stderr.","created_at":"2016-11-14T04:54:44Z","updated_at":"2016-11-26T05:02:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30abae1b8d90428fbb7b9a9bd3f40c2b857c0e82","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/facebook/osquery/pulls/2749/commits","review_comments_url":"https://api.github.com/repos/facebook/osquery/pulls/2749/comments","review_comment_url":"https://api.github.com/repos/facebook/osquery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/osquery/issues/2749/comments","statuses_url":"https://api.github.com/repos/facebook/osquery/statuses/1c6fa2b29c1776f8b1ca2586ba448a8a73f6ca86","head":{"label":"lambda-conjecture:rocksdb_deadlock_fix","ref":"rocksdb_deadlock_fix","sha":"1c6fa2b29c1776f8b1ca2586ba448a8a73f6ca86","user":{"login":"lambda-conjecture","id":22373129,"avatar_url":"https://avatars.githubusercontent.com/u/22373129?v=3","gravatar_id":"","url":"https://api.github.com/users/lambda-conjecture","html_url":"https://github.com/lambda-conjecture","followers_url":"https://api.github.com/users/lambda-conjecture/followers","following_url":"https://api.github.com/users/lambda-conjecture/following{/other_user}","gists_url":"https://api.github.com/users/lambda-conjecture/gists{/gist_id}","starred_url":"https://api.github.com/users/lambda-conjecture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lambda-conjecture/subscriptions","organizations_url":"https://api.github.com/users/lambda-conjecture/orgs","repos_url":"https://api.github.com/users/lambda-conjecture/repos","events_url":"https://api.github.com/users/lambda-conjecture/events{/privacy}","received_events_url":"https://api.github.com/users/lambda-conjecture/received_events","type":"User","site_admin":false},"repo":{"id":68930083,"name":"osquery","full_name":"lambda-conjecture/osquery","owner":{"login":"lambda-conjecture","id":22373129,"avatar_url":"https://avatars.githubusercontent.com/u/22373129?v=3","gravatar_id":"","url":"https://api.github.com/users/lambda-conjecture","html_url":"https://github.com/lambda-conjecture","followers_url":"https://api.github.com/users/lambda-conjecture/followers","following_url":"https://api.github.com/users/lambda-conjecture/following{/other_user}","gists_url":"https://api.github.com/users/lambda-conjecture/gists{/gist_id}","starred_url":"https://api.github.com/users/lambda-conjecture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lambda-conjecture/subscriptions","organizations_url":"https://api.github.com/users/lambda-conjecture/orgs","repos_url":"https://api.github.com/users/lambda-conjecture/repos","events_url":"https://api.github.com/users/lambda-conjecture/events{/privacy}","received_events_url":"https://api.github.com/users/lambda-conjecture/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lambda-conjecture/osquery","description":"SQL powered operating system instrumentation, monitoring, and analytics.","fork":true,"url":"https://api.github.com/repos/lambda-conjecture/osquery","forks_url":"https://api.github.com/repos/lambda-conjecture/osquery/forks","keys_url":"https://api.github.com/repos/lambda-conjecture/osquery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lambda-conjecture/osquery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lambda-conjecture/osquery/teams","hooks_url":"https://api.github.com/repos/lambda-conjecture/osquery/hooks","issue_events_url":"https://api.github.com/repos/lambda-conjecture/osquery/issues/events{/number}","events_url":"https://api.github.com/repos/lambda-conjecture/osquery/events","assignees_url":"https://api.github.com/repos/lambda-conjecture/osquery/assignees{/user}","branches_url":"https://api.github.com/repos/lambda-conjecture/osquery/branches{/branch}","tags_url":"https://api.github.com/repos/lambda-conjecture/osquery/tags","blobs_url":"https://api.github.com/repos/lambda-conjecture/osquery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lambda-conjecture/osquery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lambda-conjecture/osquery/git/refs{/sha}","trees_url":"https://api.github.com/repos/lambda-conjecture/osquery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lambda-conjecture/osquery/statuses/{sha}","languages_url":"https://api.github.com/repos/lambda-conjecture/osquery/languages","stargazers_url":"https://api.github.com/repos/lambda-conjecture/osquery/stargazers","contributors_url":"https://api.github.com/repos/lambda-conjecture/osquery/contributors","subscribers_url":"https://api.github.com/repos/lambda-conjecture/osquery/subscribers","subscription_url":"https://api.github.com/repos/lambda-conjecture/osquery/subscription","commits_url":"https://api.github.com/repos/lambda-conjecture/osquery/commits{/sha}","git_commits_url":"https://api.github.com/repos/lambda-conjecture/osquery/git/commits{/sha}","comments_url":"https://api.github.com/repos/lambda-conjecture/osquery/comments{/number}","issue_comment_url":"https://api.github.com/repos/lambda-conjecture/osquery/issues/comments{/number}","contents_url":"https://api.github.com/repos/lambda-conjecture/osquery/contents/{+path}","compare_url":"https://api.github.com/repos/lambda-conjecture/osquery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lambda-conjecture/osquery/merges","archive_url":"https://api.github.com/repos/lambda-conjecture/osquery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lambda-conjecture/osquery/downloads","issues_url":"https://api.github.com/repos/lambda-conjecture/osquery/issues{/number}","pulls_url":"https://api.github.com/repos/lambda-conjecture/osquery/pulls{/number}","milestones_url":"https://api.github.com/repos/lambda-conjecture/osquery/milestones{/number}","notifications_url":"https://api.github.com/repos/lambda-conjecture/osquery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lambda-conjecture/osquery/labels{/name}","releases_url":"https://api.github.com/repos/lambda-conjecture/osquery/releases{/id}","deployments_url":"https://api.github.com/repos/lambda-conjecture/osquery/deployments","created_at":"2016-09-22T14:36:02Z","updated_at":"2016-09-22T14:36:06Z","pushed_at":"2016-11-24T15:47:27Z","git_url":"git://github.com/lambda-conjecture/osquery.git","ssh_url":"git@github.com:lambda-conjecture/osquery.git","clone_url":"https://github.com/lambda-conjecture/osquery.git","svn_url":"https://github.com/lambda-conjecture/osquery","homepage":"https://osquery.io","size":9563,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"ac8c0871a6bed7624ab61b474d3c270c9f5356c1","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":22394357,"name":"osquery","full_name":"facebook/osquery","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/osquery","description":"SQL powered operating system instrumentation, monitoring, and analytics.","fork":false,"url":"https://api.github.com/repos/facebook/osquery","forks_url":"https://api.github.com/repos/facebook/osquery/forks","keys_url":"https://api.github.com/repos/facebook/osquery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/osquery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/osquery/teams","hooks_url":"https://api.github.com/repos/facebook/osquery/hooks","issue_events_url":"https://api.github.com/repos/facebook/osquery/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/osquery/events","assignees_url":"https://api.github.com/repos/facebook/osquery/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/osquery/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/osquery/tags","blobs_url":"https://api.github.com/repos/facebook/osquery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/osquery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/osquery/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/osquery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/osquery/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/osquery/languages","stargazers_url":"https://api.github.com/repos/facebook/osquery/stargazers","contributors_url":"https://api.github.com/repos/facebook/osquery/contributors","subscribers_url":"https://api.github.com/repos/facebook/osquery/subscribers","subscription_url":"https://api.github.com/repos/facebook/osquery/subscription","commits_url":"https://api.github.com/repos/facebook/osquery/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/osquery/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/osquery/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/osquery/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/osquery/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/osquery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/osquery/merges","archive_url":"https://api.github.com/repos/facebook/osquery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/osquery/downloads","issues_url":"https://api.github.com/repos/facebook/osquery/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/osquery/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/osquery/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/osquery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/osquery/labels{/name}","releases_url":"https://api.github.com/repos/facebook/osquery/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/osquery/deployments","created_at":"2014-07-29T20:27:33Z","updated_at":"2016-11-25T23:17:06Z","pushed_at":"2016-11-25T23:50:48Z","git_url":"git://github.com/facebook/osquery.git","ssh_url":"git@github.com:facebook/osquery.git","clone_url":"https://github.com/facebook/osquery.git","svn_url":"https://github.com/facebook/osquery","homepage":"https://osquery.io","size":13859,"stargazers_count":7458,"watchers_count":7458,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":850,"mirror_url":null,"open_issues_count":75,"forks":850,"open_issues":75,"watchers":7458,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/osquery/pulls/2749"},"html":{"href":"https://github.com/facebook/osquery/pull/2749"},"issue":{"href":"https://api.github.com/repos/facebook/osquery/issues/2749"},"comments":{"href":"https://api.github.com/repos/facebook/osquery/issues/2749/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/osquery/pulls/2749/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/osquery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/osquery/pulls/2749/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/osquery/statuses/1c6fa2b29c1776f8b1ca2586ba448a8a73f6ca86"}}}}
{"actor":{"display_login":"theopolis"}}