Просмотр исходного кода

Merge branch 'medusa-timeout' of git://github.com/sfriesel/supervisor into sfriesel-medusa-timeout

Mike Naberezny 9 лет назад
Родитель
Сommit
283d052601
2 измененных файлов с 6 добавлено и 1 удалено
  1. 2 0
      supervisor/medusa/CHANGES.txt
  2. 4 1
      supervisor/medusa/http_server.py

+ 2 - 0
supervisor/medusa/CHANGES.txt

@@ -6,6 +6,8 @@ PATCHES MADE ONLY TO THIS MEDUSA PACKAGE BUNDLED WITH SUPERVISOR
 * Removed medusa files not used by Supervisor.
 * Fixed a bug in auth_handler.py where colons could not be used in passwords
   for HTTP Basic authentication (Supervisor issue #309).
+* Time out connections based on inactivity instead of age (Supervisor issue
+  #651).
 
 Version 0.5.5:
 

+ 4 - 1
supervisor/medusa/http_server.py

@@ -474,6 +474,7 @@ class http_channel (asynchat.async_chat):
         self.set_terminator ('\r\n\r\n')
         self.in_buffer = ''
         self.creation_time = int (time.time())
+        self.last_used = self.creation_time
         self.check_maintenance()
 
     def __repr__ (self):
@@ -501,7 +502,7 @@ class http_channel (asynchat.async_chat):
         now = int (time.time())
         for channel in asyncore.socket_map.values():
             if channel.__class__ == self.__class__:
-                if (now - channel.creation_time) > channel.zombie_timeout:
+                if (now - channel.last_used) > channel.zombie_timeout:
                     channel.close()
 
     # --------------------------------------------------
@@ -513,12 +514,14 @@ class http_channel (asynchat.async_chat):
     def send (self, data):
         result = asynchat.async_chat.send (self, data)
         self.server.bytes_out.increment (len(data))
+        self.last_used = int (time.time())
         return result
 
     def recv (self, buffer_size):
         try:
             result = asynchat.async_chat.recv (self, buffer_size)
             self.server.bytes_in.increment (len(result))
+            self.last_used = int (time.time())
             return result
         except MemoryError:
             # --- Save a Trip to Your Service Provider ---