{"action":"created","issue":{"url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/501","repository_url":"https://api.github.com/repos/Metaswitch/cpp-common","labels_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/501/labels{/name}","comments_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/501/comments","events_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/501/events","html_url":"https://github.com/Metaswitch/cpp-common/pull/501","id":148838108,"number":501,"title":"[Reviewer: Matt] Asynchronous DNS query","user":{"login":"rkd-msw","id":4363492,"avatar_url":"https://avatars.githubusercontent.com/u/4363492?v=3","gravatar_id":"","url":"https://api.github.com/users/rkd-msw","html_url":"https://github.com/rkd-msw","followers_url":"https://api.github.com/users/rkd-msw/followers","following_url":"https://api.github.com/users/rkd-msw/following{/other_user}","gists_url":"https://api.github.com/users/rkd-msw/gists{/gist_id}","starred_url":"https://api.github.com/users/rkd-msw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkd-msw/subscriptions","organizations_url":"https://api.github.com/users/rkd-msw/orgs","repos_url":"https://api.github.com/users/rkd-msw/repos","events_url":"https://api.github.com/users/rkd-msw/events{/privacy}","received_events_url":"https://api.github.com/users/rkd-msw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"rkd-msw","id":4363492,"avatar_url":"https://avatars.githubusercontent.com/u/4363492?v=3","gravatar_id":"","url":"https://api.github.com/users/rkd-msw","html_url":"https://github.com/rkd-msw","followers_url":"https://api.github.com/users/rkd-msw/followers","following_url":"https://api.github.com/users/rkd-msw/following{/other_user}","gists_url":"https://api.github.com/users/rkd-msw/gists{/gist_id}","starred_url":"https://api.github.com/users/rkd-msw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkd-msw/subscriptions","organizations_url":"https://api.github.com/users/rkd-msw/orgs","repos_url":"https://api.github.com/users/rkd-msw/repos","events_url":"https://api.github.com/users/rkd-msw/events{/privacy}","received_events_url":"https://api.github.com/users/rkd-msw/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2016-04-16T09:49:00Z","updated_at":"2016-05-13T16:28:49Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/501","html_url":"https://github.com/Metaswitch/cpp-common/pull/501","diff_url":"https://github.com/Metaswitch/cpp-common/pull/501.diff","patch_url":"https://github.com/Metaswitch/cpp-common/pull/501.patch"},"body":"This implements the fix you suggested in https://github.com/Metaswitch/sprout/issues/1399#issuecomment-210478766.\r\n\r\nI haven't done any live testing yet - I was thinking of writing a small tool that started 30 threads, all sharing a resolver, which query for cw-ngv.com and staging.cw-ngv.com (DNS TTL 60 seconds) once a second for ten minutes. I'd then:\r\n\r\n* check that they never got an empty or otherwise incorrect result\r\n* run that test program under Helgrind and memcheck\r\n* check the logs and/or use gcov to make sure my new code is being hit\r\n\r\nI might artificially slow down DNS responses if they come back too fast for me to test this change."},"comment":{"url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/comments/219092926","html_url":"https://github.com/Metaswitch/cpp-common/pull/501#issuecomment-219092926","issue_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/501","id":219092926,"user":{"login":"rkd-msw","id":4363492,"avatar_url":"https://avatars.githubusercontent.com/u/4363492?v=3","gravatar_id":"","url":"https://api.github.com/users/rkd-msw","html_url":"https://github.com/rkd-msw","followers_url":"https://api.github.com/users/rkd-msw/followers","following_url":"https://api.github.com/users/rkd-msw/following{/other_user}","gists_url":"https://api.github.com/users/rkd-msw/gists{/gist_id}","starred_url":"https://api.github.com/users/rkd-msw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkd-msw/subscriptions","organizations_url":"https://api.github.com/users/rkd-msw/orgs","repos_url":"https://api.github.com/users/rkd-msw/repos","events_url":"https://api.github.com/users/rkd-msw/events{/privacy}","received_events_url":"https://api.github.com/users/rkd-msw/received_events","type":"User","site_admin":false},"created_at":"2016-05-13T16:28:49Z","updated_at":"2016-05-13T16:28:49Z","body":"Test code was:\r\n\r\n```\r\n#include \"dnscachedresolver.h\"\r\n#include <cassert>\r\n#include <unistd.h>\r\n#include <thread>\r\n\r\nstatic DnsCachedResolver* d;\r\n\r\nvoid resolver_thread_function()\r\n{\r\n  for (int i = 0; i < 10; i++)\r\n  {\r\n    DnsResult r = d->dns_query(\"cw-ngv.com\", ns_t_a);\r\n    TRC_INFO(\"Got %ld records\\n\", r.records().size());\r\n    DnsResult r2 = d->dns_query(\"staging.cw-ngv.com\", ns_t_a);\r\n    TRC_INFO(\"Got %ld records\\n\", r2.records().size());\r\n    assert(r.records().size() > 0);\r\n    assert(r2.records().size() > 0);\r\n    sleep(60);\r\n  }\r\n}\r\n\r\nint main()\r\n{\r\n  d = new DnsCachedResolver(\"8.8.8.8\");\r\n  std::vector<std::thread*> threads;\r\n  for (int i = 0; i < 30; i++)\r\n  {\r\n    threads.push_back(new std::thread(resolver_thread_function));\r\n  }\r\n\r\n  for (std::thread* t: threads)\r\n  {\r\n    t->join();\r\n    delete t;\r\n  }\r\n\r\n  delete d;\r\n}\r\n```"}}