{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/214583771","pull_request_review_id":151668812,"id":214583771,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDU4Mzc3MQ==","diff_hunk":"@@ -432,25 +434,44 @@ func createServer() {\n \t}\n }\n \n-func setupSignalHandler() {\n+func setupSignalHandler(ctx context.Context) {\n \tsc := make(chan os.Signal, 1)\n \tsignal.Notify(sc,\n \t\tsyscall.SIGHUP,\n \t\tsyscall.SIGINT,\n \t\tsyscall.SIGTERM,\n-\t\tsyscall.SIGQUIT)\n+\t\tsyscall.SIGQUIT,\n+\t\tsyscall.SIGUSR1)\n \n \tgo func() {\n-\t\tsig := <-sc\n-\t\tlog.Infof(\"Got signal [%s] to exit.\", sig)\n-\t\tif sig == syscall.SIGQUIT {\n-\t\t\tgraceful = true\n-\t\t}\n-\n-\t\tif xsvr != nil {\n-\t\t\txsvr.Close() // Should close xserver before server.\n+\t\tquited := false\n+\t\tfor {\n+\t\t\tselect {\n+\t\t\tcase sig := <-sc:\n+\t\t\t\tif sig == syscall.SIGUSR1 {\n+\t\t\t\t\tbuf := make([]byte, 1<<20)","path":"tidb-server/main.go","position":58,"original_position":58,"commit_id":"44571b12bb13c23a876bb11800e59e4d2edd6cb8","original_commit_id":"44571b12bb13c23a876bb11800e59e4d2edd6cb8","user":{"login":"jackysp","id":4352397,"node_id":"MDQ6VXNlcjQzNTIzOTc=","avatar_url":"https://avatars1.githubusercontent.com/u/4352397?v=4","gravatar_id":"","url":"https://api.github.com/users/jackysp","html_url":"https://github.com/jackysp","followers_url":"https://api.github.com/users/jackysp/followers","following_url":"https://api.github.com/users/jackysp/following{/other_user}","gists_url":"https://api.github.com/users/jackysp/gists{/gist_id}","starred_url":"https://api.github.com/users/jackysp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackysp/subscriptions","organizations_url":"https://api.github.com/users/jackysp/orgs","repos_url":"https://api.github.com/users/jackysp/repos","events_url":"https://api.github.com/users/jackysp/events{/privacy}","received_events_url":"https://api.github.com/users/jackysp/received_events","type":"User","site_admin":false},"body":"This may cause a deadlock.","created_at":"2018-09-03T06:10:28Z","updated_at":"2018-09-03T06:10:28Z","html_url":"https://github.com/pingcap/tidb/pull/7587#discussion_r214583771","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/7587","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/214583771"},"html":{"href":"https://github.com/pingcap/tidb/pull/7587#discussion_r214583771"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7587"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/7587","id":212632462,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyNjMyNDYy","html_url":"https://github.com/pingcap/tidb/pull/7587","diff_url":"https://github.com/pingcap/tidb/pull/7587.diff","patch_url":"https://github.com/pingcap/tidb/pull/7587.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/7587","number":7587,"state":"open","locked":false,"title":"server: add USR1 signal handler to dump goroutine","user":{"login":"lysu","id":528332,"node_id":"MDQ6VXNlcjUyODMzMg==","avatar_url":"https://avatars3.githubusercontent.com/u/528332?v=4","gravatar_id":"","url":"https://api.github.com/users/lysu","html_url":"https://github.com/lysu","followers_url":"https://api.github.com/users/lysu/followers","following_url":"https://api.github.com/users/lysu/following{/other_user}","gists_url":"https://api.github.com/users/lysu/gists{/gist_id}","starred_url":"https://api.github.com/users/lysu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lysu/subscriptions","organizations_url":"https://api.github.com/users/lysu/orgs","repos_url":"https://api.github.com/users/lysu/repos","events_url":"https://api.github.com/users/lysu/events{/privacy}","received_events_url":"https://api.github.com/users/lysu/received_events","type":"User","site_admin":false},"body":"### What problem does this PR solve? <!--add issue link with summary if exists-->\r\n\r\nrelate to #7558, we add USR1 signal handler to dump goroutine stack into stdout.\r\n\r\n### What is changed and how it works?\r\n\r\n- doesn't exit signal handler goroutine until cleanup down\r\n- handle USR1 signal and dump groutine into stdout\r\n\r\n### Check List <!--REMOVE the items that are not applicable-->\r\n\r\nTests <!-- At least one of them must be included. -->\r\n\r\n - Manual test (add detailed scripts or steps below)\r\n\r\n1) `pkill -USR1 tidb-server` to send signal and check stdout see\r\n\r\n```\r\n2018/09/03 11:20:06.150  [info] === Got signal [user defined signal 1] to thread dump===\r\n*** goroutine dump...\r\ngoroutine 107 [running]:\r\nmain.setupSignalHandler.func1(0xc4200f8e40, 0x14cdd80, 0xc4200dfec0)\r\n\t/home/robi/Code/go/src/github.com/pingcap/tidb/tidb-server/main.go:453 +0x2d8\r\ncreated by main.setupSignalHandler\r\n\t/home/robi/Code/go/src/github.com/pingcap/tidb/tidb-server/main.go:446 +0x12e\r\n\r\ngoroutine 1 [sleep, 10 minutes]:\r\ntime.Sleep(0x1176592e000)\r\n\t/home/robi/go1.10/src/runtime/time.go:102 +0x166\r\nmain.cleanup()\r\n\t/home/robi/Code/go/src/github.com/pingcap/tidb/tidb-server/main.go:526 +0x3b\r\nmain.main()\r\n\t/home/robi/Code/go/src/github.com/pingcap/tidb/tidb-server/main.go:147 +0xbc\r\n\r\ngoroutine 18 [syscall]:\r\nos/signal.signal_recv(0x14c2840)\r\n\t/home/robi/go1.10/src/runtime/sigqueue.go:139 +0xa6\r\nos/signal.loop()\r\n\t/home/robi/go1.10/src/os/signal/signal_unix.go:22 +0x22\r\ncreated by os/signal.init.0\r\n\t/home/robi/go1.10/src/os/signal/signal_unix.go:28 +0x41\r\n\r\ngoroutine 114 [chan receive]:\r\ngithub.com/pingcap/tidb/util/systimemon.StartMonitor(0x1410138, 0x140f6a8, 0xc420038f20)\r\n\t/home/robi/Code/go/src/github.com/pingcap/tidb/util/systimemon/systime_mon.go:30 +0x154\r\ncreated by main.setupMetrics\r\n\t/home/robi/Code/go/src/github.com/pingcap/tidb/tidb-server/main.go:493 +0xb5\r\n......\r\n``` \r\n\r\n2) temporal add `Sleep(time.Mintue*20) in cleanup(main.go).` \r\n3) `pkill -QUIT tidb-server` to shutdown tidb-server\r\n4) `pkill -USR1 tidb-server` again and got dump output too\r\n\r\nCode changes\r\n\r\n - signal handler change\r\n\r\nSide effects\r\n\r\n - no\r\n\r\nRelated changes\r\n\r\n - no\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/pingcap/tidb/7587)\n<!-- Reviewable:end -->\n","created_at":"2018-09-03T03:23:54Z","updated_at":"2018-09-03T06:10:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6ac481392c2d06df0b14d7f0167931e41f7bd709","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":799107676,"node_id":"MDU6TGFiZWw3OTkxMDc2NzY=","url":"https://api.github.com/repos/pingcap/tidb/labels/component/tools","name":"component/tools","color":"cbf232","default":false},{"id":564574080,"node_id":"MDU6TGFiZWw1NjQ1NzQwODA=","url":"https://api.github.com/repos/pingcap/tidb/labels/status/LGT1","name":"status/LGT1","color":"d4c5f9","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/7587/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/7587/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/7587/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/44571b12bb13c23a876bb11800e59e4d2edd6cb8","head":{"label":"lysu:dev-add-thread-dump-signal","ref":"dev-add-thread-dump-signal","sha":"44571b12bb13c23a876bb11800e59e4d2edd6cb8","user":{"login":"lysu","id":528332,"node_id":"MDQ6VXNlcjUyODMzMg==","avatar_url":"https://avatars3.githubusercontent.com/u/528332?v=4","gravatar_id":"","url":"https://api.github.com/users/lysu","html_url":"https://github.com/lysu","followers_url":"https://api.github.com/users/lysu/followers","following_url":"https://api.github.com/users/lysu/following{/other_user}","gists_url":"https://api.github.com/users/lysu/gists{/gist_id}","starred_url":"https://api.github.com/users/lysu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lysu/subscriptions","organizations_url":"https://api.github.com/users/lysu/orgs","repos_url":"https://api.github.com/users/lysu/repos","events_url":"https://api.github.com/users/lysu/events{/privacy}","received_events_url":"https://api.github.com/users/lysu/received_events","type":"User","site_admin":false},"repo":{"id":133315666,"node_id":"MDEwOlJlcG9zaXRvcnkxMzMzMTU2NjY=","name":"tidb","full_name":"lysu/tidb","owner":{"login":"lysu","id":528332,"node_id":"MDQ6VXNlcjUyODMzMg==","avatar_url":"https://avatars3.githubusercontent.com/u/528332?v=4","gravatar_id":"","url":"https://api.github.com/users/lysu","html_url":"https://github.com/lysu","followers_url":"https://api.github.com/users/lysu/followers","following_url":"https://api.github.com/users/lysu/following{/other_user}","gists_url":"https://api.github.com/users/lysu/gists{/gist_id}","starred_url":"https://api.github.com/users/lysu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lysu/subscriptions","organizations_url":"https://api.github.com/users/lysu/orgs","repos_url":"https://api.github.com/users/lysu/repos","events_url":"https://api.github.com/users/lysu/events{/privacy}","received_events_url":"https://api.github.com/users/lysu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lysu/tidb","description":"TiDB is a distributed HTAP database compatible with the MySQL protocol ","fork":true,"url":"https://api.github.com/repos/lysu/tidb","forks_url":"https://api.github.com/repos/lysu/tidb/forks","keys_url":"https://api.github.com/repos/lysu/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lysu/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lysu/tidb/teams","hooks_url":"https://api.github.com/repos/lysu/tidb/hooks","issue_events_url":"https://api.github.com/repos/lysu/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/lysu/tidb/events","assignees_url":"https://api.github.com/repos/lysu/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/lysu/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/lysu/tidb/tags","blobs_url":"https://api.github.com/repos/lysu/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lysu/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lysu/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/lysu/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lysu/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/lysu/tidb/languages","stargazers_url":"https://api.github.com/repos/lysu/tidb/stargazers","contributors_url":"https://api.github.com/repos/lysu/tidb/contributors","subscribers_url":"https://api.github.com/repos/lysu/tidb/subscribers","subscription_url":"https://api.github.com/repos/lysu/tidb/subscription","commits_url":"https://api.github.com/repos/lysu/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/lysu/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/lysu/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/lysu/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/lysu/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/lysu/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lysu/tidb/merges","archive_url":"https://api.github.com/repos/lysu/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lysu/tidb/downloads","issues_url":"https://api.github.com/repos/lysu/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/lysu/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/lysu/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/lysu/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lysu/tidb/labels{/name}","releases_url":"https://api.github.com/repos/lysu/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/lysu/tidb/deployments","created_at":"2018-05-14T06:37:16Z","updated_at":"2018-08-31T13:23:03Z","pushed_at":"2018-09-03T06:10:21Z","git_url":"git://github.com/lysu/tidb.git","ssh_url":"git@github.com:lysu/tidb.git","clone_url":"https://github.com/lysu/tidb.git","svn_url":"https://github.com/lysu/tidb","homepage":"https://pingcap.com","size":56002,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"621ca431ad8f92a00b7b8349fd891e9ee863f630","user":{"login":"pingcap","id":11855343,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExODU1MzQz","avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"node_id":"MDEwOlJlcG9zaXRvcnk0MTk4NjM2OQ==","name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExODU1MzQz","avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed HTAP database compatible with the MySQL protocol ","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tidb/deployments","created_at":"2015-09-06T04:01:52Z","updated_at":"2018-09-03T05:57:05Z","pushed_at":"2018-09-03T06:10:23Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"https://pingcap.com","size":80972,"stargazers_count":14660,"watchers_count":14660,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2042,"mirror_url":null,"archived":false,"open_issues_count":539,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":2042,"open_issues":539,"watchers":14660,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7587"},"html":{"href":"https://github.com/pingcap/tidb/pull/7587"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/7587"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/7587/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7587/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/7587/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/44571b12bb13c23a876bb11800e59e4d2edd6cb8"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"jackysp"}}