{"action":"closed","issue":{"url":"https://api.github.com/repos/boostorg/asio/issues/314","repository_url":"https://api.github.com/repos/boostorg/asio","labels_url":"https://api.github.com/repos/boostorg/asio/issues/314/labels{/name}","comments_url":"https://api.github.com/repos/boostorg/asio/issues/314/comments","events_url":"https://api.github.com/repos/boostorg/asio/issues/314/events","html_url":"https://github.com/boostorg/asio/issues/314","id":543069865,"node_id":"MDU6SXNzdWU1NDMwNjk4NjU=","number":314,"title":"deadline timer cause infinteloop","user":{"login":"jaycelq","id":4169335,"node_id":"MDQ6VXNlcjQxNjkzMzU=","avatar_url":"https://avatars1.githubusercontent.com/u/4169335?v=4","gravatar_id":"","url":"https://api.github.com/users/jaycelq","html_url":"https://github.com/jaycelq","followers_url":"https://api.github.com/users/jaycelq/followers","following_url":"https://api.github.com/users/jaycelq/following{/other_user}","gists_url":"https://api.github.com/users/jaycelq/gists{/gist_id}","starred_url":"https://api.github.com/users/jaycelq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaycelq/subscriptions","organizations_url":"https://api.github.com/users/jaycelq/orgs","repos_url":"https://api.github.com/users/jaycelq/repos","events_url":"https://api.github.com/users/jaycelq/events{/privacy}","received_events_url":"https://api.github.com/users/jaycelq/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-12-28T05:30:14Z","updated_at":"2019-12-30T12:37:06Z","closed_at":"2019-12-30T12:37:06Z","author_association":"NONE","body":"https://github.com/chriskohlhoff/asio/issues/448#issue-543066986\r\n\r\nI use deadline timer in my project, and it will cause infinite loop occasionally in function get_ready_times.\r\n\r\nI guess the heap or the list is corrupted. So I add some log and assert in timer_queue.hpp\r\n```\r\n  void hpPrintHeapInfo()\r\n  {\r\n      for (std::size_t i = 0; i < heap_.size(); ++i)\r\n      {\r\n          per_timer_data* timer = heap_[i].timer_;\r\n          std::cout << \"thread: \" << syscall(SYS_gettid) << \" heap[\" << i << \"].timer_->heap_index_: \" << timer->heap_index_\r\n                    << \" time: \" << Time_Traits::to_posix_duration(Time_Traits::subtract(heap_[i].time_, Time_Traits::now())).total_milliseconds() \r\n                    << \" per_timer_data addr:\" << timer << std::endl;\r\n      }\r\n      for (std::size_t i = 0; i < heap_.size(); ++i)\r\n      {\r\n          per_timer_data* timer = heap_[i].timer_;\r\n          assert(timer->heap_index_ == i);\r\n      }\r\n      std::cout << \"thread: \" << syscall(SYS_gettid) << \"hpPrintHeapInfo over\" << std::endl;\r\n  }\r\n\r\n  void hpPrintListInfo()\r\n  {\r\n      for (per_timer_data* p = timers_; p; p = p->next_)\r\n      {\r\n          std::cout << \"thread: \" << syscall(SYS_gettid) << \" addr: \" << p << \" heap_index: \" << p->heap_index_ << std::endl;\r\n      }\r\n  }\r\n\r\n...\r\n  // Remove a timer from the heap and list of timers.\r\n  void remove_timer(per_timer_data& timer)\r\n  {\r\n    // Remove the timer from the heap.\r\n    std::size_t index = timer.heap_index_;\r\n    std::cout << \"thread: \" << syscall(SYS_gettid) << \" remove_timer index: \" << index << \" addr: \" << &timer << std::endl;\r\n    if (!heap_.empty() && index < heap_.size())\r\n    {\r\n      if (index == heap_.size() - 1)\r\n      {\r\n        timer.heap_index_ = (std::numeric_limits<std::size_t>::max)();\r\n        heap_.pop_back();\r\n      }\r\n      else\r\n      {\r\n        swap_heap(index, heap_.size() - 1);\r\n        timer.heap_index_ = (std::numeric_limits<std::size_t>::max)();\r\n        heap_.pop_back();\r\n        if (index > 0 && Time_Traits::less_than(\r\n              heap_[index].time_, heap_[(index - 1) / 2].time_))\r\n          up_heap(index);\r\n        else\r\n          down_heap(index);\r\n      }\r\n    }\r\n\r\n    // Remove the timer from the linked list of active timers.\r\n    if (timers_ == &timer)\r\n      timers_ = timer.next_;\r\n    if (timer.prev_)\r\n      timer.prev_->next_ = timer.next_;\r\n    if (timer.next_)\r\n      timer.next_->prev_= timer.prev_;\r\n    timer.next_ = 0;\r\n    timer.prev_ = 0;\r\n    \r\n    hpPrintListInfo();\r\n    hpPrintHeapInfo();\r\n  }\r\n```\r\n\r\nAnd I get the log when the assertion is not satisfied. It seems the heap is corrupted unexpectedly and the list lost the last element, but I cannot figure out why this happened. I think this is a fatal problem, can any one help me with that issue? @chriskohlhoff \r\n```\r\nthread: 12965 enqueue_timer heap_index_: 5 addr:0x61500001ffd8\r\nthread: 12965 addr: 0x61500001ffd8 heap_index: 5\r\nthread: 12965 addr: 0x615000022558 heap_index: 4\r\nthread: 12965 addr: 0x615000024858 heap_index: 3\r\nthread: 12965 addr: 0x7f50bc8f18e8 heap_index: 0\r\nthread: 12965 addr: 0x6150000204d8 heap_index: 1\r\nthread: 12965 addr: 0x615000024358 heap_index: 2\r\nthread: 12965 heap[0].timer_->heap_index_: 0 time: 514 per_timer_data addr:0x7f50bc8f18e8\r\nthread: 12965 heap[1].timer_->heap_index_: 1 time: 7996 per_timer_data addr:0x6150000204d8\r\nthread: 12965 heap[2].timer_->heap_index_: 2 time: 7996 per_timer_data addr:0x615000024358\r\nthread: 12965 heap[3].timer_->heap_index_: 3 time: 9799 per_timer_data addr:0x615000024858\r\nthread: 12965 heap[4].timer_->heap_index_: 4 time: 9999 per_timer_data addr:0x615000022558\r\nthread: 12965 heap[5].timer_->heap_index_: 5 time: 9999 per_timer_data addr:0x61500001ffd8\r\nthread: 12965hpPrintHeapInfo over\r\nthread: 12965 get_ready_timers begin, heap size: 6\r\nthread: 12965 remove_timer index: 0 addr: 0x7f50bc8f18e8\r\nthread: 12965 addr: 0x61500001ffd8 heap_index: 2\r\nthread: 12965 addr: 0x615000022558 heap_index: 4\r\nthread: 12965 addr: 0x615000024858 heap_index: 3\r\nthread: 12965 addr: 0x6150000204d8 heap_index: 18446744073709551615\r\nthread: 12965 heap[0].timer_->heap_index_: 0 time: 7464 per_timer_data addr:0x615000024358\r\nthread: 12965 heap[1].timer_->heap_index_: 18446744073709551615 time: 7464 per_timer_data addr:0x6150000204d8\r\nthread: 12965 heap[2].timer_->heap_index_: 2 time: 9468 per_timer_data addr:0x61500001ffd8\r\nthread: 12965 heap[3].timer_->heap_index_: 3 time: 9267 per_timer_data addr:0x615000024858\r\nthread: 12965 heap[4].timer_->heap_index_: 4 time: 9467 per_timer_data addr:0x615000022558\r\nnodeserver: /home/data/jenkins/jenkins_server_code/workspace/hk4e_trunk/../hk4e_ext/boost/../boost_1_70_0d/boost/asio/detail/timer_queue.hpp:93: void boost::asio::detail::timer_queue<Time_Traits>::hpPrintHeapInfo() [with Time_Traits = boost::asio::detail::forwarding_posix_time_traits]: Assertion `timer->heap_index_ == i' failed.\r\n```\r\n"}}
{"actor":{"display_login":"jaycelq"}}