{"id":7352,"date":"2019-07-23T09:51:27","date_gmt":"2019-07-23T16:51:27","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=7352"},"modified":"2019-07-23T09:51:27","modified_gmt":"2019-07-23T16:51:27","slug":"detect-endless-loop","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/detect-endless-loop\/","title":{"rendered":"Q&#038;A: Why Doesn&#8217;t AlwaysUp Catch my Endless Loop?"},"content":{"rendered":"<div align=\"center\"><img decoding=\"async\" src=\"\/blog\/images\/qa-no-infinite-loop.png\" title=\"Q &#038; A - Detect Infinite Loops\" alt=\"Q &#038; A - Detect Infinite Loops\" border=\"0\" ><\/div>\n<div class=\"blog-qa-question-box\">\n<img decoding=\"async\" src=\"\/images\/quotes-transparent-21x21.png\">&nbsp;&nbsp;Following your <a href=\"\/products\/AlwaysUp\/AlwaysUpUserManual.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">AlwaysUp documentation<\/a>, I am using the &#8220;Monitor the application and stop it whenever it hangs&#8221; option. When I set its value to 1 minute, this feature does not work as I expect.<\/p>\n<p>I wrote a simple application that goes into an endless loop after one minute of execution time. But the application is not restarted by AlwaysUp. Why not?<\/p>\n<p align=\"right\">&#8212; Beatrix<\/p>\n<\/div>\n<p>Hi Beatrix. Not all infinite loops can be detected by AlwaysUp. Let me explain&#8230;<\/p>\n<h2 class=\"blog-caption\">AlwaysUp catches non-responsive GUI applications<\/h2>\n<p>AlwaysUp&#8217;s hang detection feature is designed to identify a specific situation &mdash; where a Windows GUI application is not responding to the operating system.<\/p>\n<p>We have all encountered this type of hang before. It happens when <a href=\"https:\/\/support.mozilla.org\/en-US\/kb\/firefox-hangs-or-not-responding\" target=\"_blank\" rel=\"noopener noreferrer\">Firefox suddenly locks up<\/a>, or when <a href=\"https:\/\/support.office.com\/en-ie\/article\/excel-not-responding-hangs-freezes-or-stops-working-37e7d3c9-9e84-40bf-a805-4ca6853a1ff4\" target=\"_blank\" rel=\"noopener noreferrer\">Excel goes gray<\/a> and the cursor turns into a spinning wheel. The application is frozen and all input is ignored.<\/p>\n<p>If you are lucky, the disruption only lasts a few seconds; if not, you may have to forcibly terminate the application from the Task Manager. Very annoying!<\/p>\n<p>Beyond the gray window and spinning cursor, there are a couple of telltale signs when an application is hung\/non-responsive:<\/p>\n<ol>\n<li>\n<p>You will see &#8220;Not responding&#8221; in the application&#8217;s title bar.<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/outlook-not-responding.png\" class=\"zoomPopup\" title=\"Outlook Not Responding\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/outlook-not-responding.png\" title=\"Outlook Not Responding (click to enlarge)\" alt=\"Outlook Not Responding\" border=\"0\" ><\/a><\/div>\n<\/li>\n<li>\n<p>The application&#8217;s process will be marked as &#8220;Not responding&#8221; in the Task Manager:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/task-manager-process-not-responding.png\" class=\"zoomPopup\" title=\"Task Manager Process Not Responding\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/task-manager-process-not-responding.png\" title=\"Task Manager Process Not Responding (click to enlarge)\" alt=\"Task Manager Process Not Responding\" border=\"0\" width=\"520\"><\/a><\/div>\n<\/li>\n<\/ol>\n<p>Furthermore, Windows may throw up a warning outlining your very limited options:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/excel-not-responding.png\" class=\"zoomPopup\" title=\"Excel  Not Responding\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/excel-not-responding.png\" title=\"Excel  Not Responding (click to enlarge)\" alt=\"Excel Process Not Responding\" border=\"0\" ><\/a><\/div>\n<p>The good news is that AlwaysUp has you covered in all of those situations!<\/p>\n<h2 class=\"blog-caption\">How AlwaysUp checks if your application is hung<\/h2>\n<p>When you enable hang-checking, the AlwaysUp Windows Service component executes the following procedure every few seconds:<\/p>\n<ol>\n<li>\n<p>Scans the desktop to identify all <a href=\"https:\/\/stackoverflow.com\/questions\/18244379\/what-exactly-is-a-top-level-window-in-win32-programming\" target=\"_blank\" rel=\"noopener noreferrer\">top-level windows<\/a> belonging to the application being monitored.<\/p>\n<\/li>\n<li>\n<p>Sends each of those top-level windows a <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/winmsg\/wm-null\" target=\"_blank\" rel=\"noopener noreferrer\">WM_NULL (no-op)<\/a> message.<\/p>\n<\/li>\n<li>\n<p>Waits a few seconds for each of the windows to acknowledge the message.<\/p>\n<\/li>\n<li>\n<p>Declares the application a hang if no windows respond.<\/p>\n<\/li>\n<\/ol>\n<p>An application that remains hung over the user-supplied duration (1 minute, in your case) will be terminated and restarted.<\/p>\n<h2 class=\"blog-caption\">Not all endless loops result in a frozen\/non-responsive application<\/h2>\n<p>There are a couple of consequences stemming from the way that AlwaysUp checks for a hang.<\/p>\n<p>First, <b>an application without a top-level window can never be classified as a hang<\/b>.<\/p>\n<p>For example, this simple, non-GUI C# program that loops forever will escape detection:<\/p>\n<div class=\"code-box\">\n<pre>\nusing System;\nnamespace InfiniteLoop {\n   class Program {\n      static void Main(string[] args) {\n         while (true) {\n            Thread.Sleep(1000);\n         }\n      }\n   }\n}\n<\/pre>\n<\/div>\n<p>Second, if an application creates multiple windows, <b>all windows must be non-responsive for AlwaysUp to declare a hang<\/b>. If even a single window processes the WM_NULL message, the application will be classified as responsive.<\/p>\n<p>My guess is that your endless loop test fits into one of the scenarios above. Unfortunately AlwaysUp&#8217;s hang detection feature will not be able to help there. Sorry about that!<\/p>\n<p>But all is not lost&#8230;<\/p>\n<h2 class=\"blog-caption\">Use the Sanity Check feature to detect endless loops and other failures<\/h2>\n<p>There can be many indications that a program is stuck. For example, an application might:<\/p>\n<ul>\n<li>\n<p>stop responding to requests over the network;<\/p>\n<\/li>\n<li>\n<p>stop writing entries to a status file;<\/p>\n<\/li>\n<li>\n<p>report an &#8220;I have failed&#8221; message to a log file;<\/p>\n<\/li>\n<li>\n<p>or leave files collecting dust in a specific &#8220;inbox&#8221; folder<\/p>\n<\/li>\n<\/ul>\n<p>In situations like these &mdash; where the failure is detectable by a script or simple utility &mdash; you should look to <a href=\"\/products\/AlwaysUp\/Plugins\/\">AlwaysUp&#8217;s powerful Sanity Check feature<\/a>. It allows you to extend failure detection to encompass anything you like, including the issues listed above.<\/p>\n<p>The <a href=\"\/products\/AlwaysUp\/Plugins\/\">Sanity Check page<\/a> digs into the technical details, which we will not repeat here. Please review the documentation and <a href=\"\/support\/\">get in touch<\/a> if you need help to use that flexible functionality.<\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/dropbox-not-working\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Dropbox Version 81.4.195 (September 18, 2019) Not Working With AlwaysUp For Some Customers\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/dropbox-experiencing-issues-150x150-150x123.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Dropbox Version 81.4.195 (September 18, 2019) Not Working With AlwaysUp For Some Customers<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/version-14-5-released\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"AlwaysUp 14.5: Smarter Starts for OneDrive, Dropbox and More\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/whats-new-release-150x150-1-150x150.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">AlwaysUp 14.5: Smarter Starts for OneDrive, Dropbox and More<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/company\/secure-software-practices\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: How Do You Make Sure Your Software Is Secure?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/security-practices-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: How Do You Make Sure Your Software Is Secure?<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;Following your AlwaysUp documentation, I am using the &#8220;Monitor the application and stop it whenever it hangs&#8221; option. When I set its value to 1 minute, this feature does not work as I expect. I wrote a simple application that &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/detect-endless-loop\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":7357,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[26,87,90,127,138],"class_list":["post-7352","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-alwaysup-tag","tag-hang-detection","tag-infinite-loops","tag-qa","tag-sanity-check"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/7352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=7352"}],"version-history":[{"count":0,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/7352\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/7357"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=7352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=7352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=7352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}