Fix rare hang in

Once in a long while, dev_server_wrapper would hang when shutting down the
devserver, which would cause VM tests on the builders to fail.

This CL includes the test script used to reproduce the original problem
(which reproduced on the 435th shutdown), and to verify the fix (which ran
though 23,342 iterations before I killed it).

TEST=Ran test script though over 23,000 start/stop iterations without hanging.

Change-Id: I17943701361c3d5ae2f63abf25904d797b46e507
Commit-Queue: Don Garrett <>
Reviewed-by: Don Garrett <>
Tested-by: Don Garrett <>
diff --git a/lib/ b/lib/
index 33032ab..4ccf528 100644
--- a/lib/
+++ b/lib/
@@ -6,7 +6,7 @@
 import os
-import threading
+import multiprocessing
 import re
 import sys
 import time
@@ -49,14 +49,14 @@
   """Thrown when the devserver fails to start up correctly."""
-class DevServerWrapper(threading.Thread):
+class DevServerWrapper(multiprocessing.Process):
   """A Simple wrapper around a dev server instance."""
   def __init__(self, test_root):
     self.proc = None
     self.test_root = test_root
     self._log_filename = os.path.join(test_root, 'dev_server.log')
-    threading.Thread.__init__(self)
+    multiprocessing.Process.__init__(self)
   def run(self):
     # Kill previous running instance of devserver if it exists.
diff --git a/lib/ b/lib/
new file mode 100755
index 0000000..0b75c3b
--- /dev/null
+++ b/lib/
@@ -0,0 +1,32 @@
+# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Stress test for dev_server_wrapper.
+Test script runs forever stressing the ability to start and stop the
+dev_server_wrapper. Even very rare hangs will cause significant build flake.
+import sys
+import constants
+from crostestutils.lib import dev_server_wrapper
+i = 0
+while True:
+  i += 1
+  print 'Iteration {}'.format(i)
+  wrapper = dev_server_wrapper.DevServerWrapper('/tmp')
+  print 'Starting'
+  wrapper.start()
+  print 'Waiting for Started'
+  wrapper.WaitUntilStarted()
+  print 'Stopping'
+  wrapper.Stop()