projectkudu/kudu — pull request #277 by suwatch (2012-12-27 01:13:08+00:00)
Title: Add IdleTimeout for process and functional test

This is to address https://github.com/projectkudu/kudu/issues/151.

Kudu launches processes (thru Executable) to perform different tasks. The issue is if the process or its child never returns or hangs, it will not be terminated; worse it may hold on to some lock such as deployment blocking future operations. In Azure environment, the process will stay forever till machine reboots. This prevents the site from spinning down.

The fix is if we detect that the process is idle, we will terminate the process and its children. We define idle as there is no activity on the process output stream. The default idle timeout is 3mins and is configurable thru deployment settings manager.

90% of the change is to propagate the Idle timeout settings to executable. The main changes are in ..

Kudu.FunctionalTests/GitRepositoryManagementTests.cs
Kudu.Core/Infrastructure/Executable.cs
Kudu.Core/Infrastructure/ProcessExtensions.cs

To kill the child process, we use performance counter to figure the process tree out. This works well on PICO and Windows 7. Other alternatives are either using ManagementObject or PInvokes. However, neither work on PICO.

Unfortunately, on Windows 8, the apppool identity does not work (fail access denied when accessing perf counters). I currently makes killing child process best effort.