Changeset 463

Show
Ignore:
Timestamp:
09/29/07 17:52:54 (1 year ago)
Author:
warner@lothar.com
Message:

web: track HTTPChannels, so we can kill them at reconfig time. Closes #102

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ChangeLog

    r462 r463  
    112007-09-29  Brian Warner  <warner@lothar.com> 
     2 
     3        * buildbot/status/web/base.py (HtmlResource.render): keep track of 
     4        HTTPChannels, so we can shut them down at reconfig time (when the 
     5        WebStatus goes away). Closes #102. 
     6        * buildbot/status/web/baseweb.py (WebStatus.__init__): same 
     7        (WebStatus.registerChannel): same 
     8        (WebStatus.stopService): do .loseConnection() here 
    29 
    310        * buildbot/test/test_webparts.py (Webparts.testPages): reload the 
  • buildbot/status/web/base.py

    r452 r463  
    175175 
    176176    def render(self, request): 
     177        # tell the WebStatus about the HTTPChannel that got opened, so they 
     178        # can close it if we get reconfigured and the WebStatus goes away. 
     179        # They keep a weakref to this, since chances are good that it will be 
     180        # closed by the browser or by us before we get reconfigured. See 
     181        # ticket #102 for details. 
     182        if hasattr(request, "channel"): 
     183            # web.distrib.Request has no .channel 
     184            request.site.buildbot_service.registerChannel(request.channel) 
    177185 
    178186        # Our pages no longer require that their URL end in a slash. Instead, 
  • buildbot/status/web/baseweb.py

    r462 r463  
    11 
    2 import os, sys, time, urllib 
     2import os, sys, time, urllib, weakref 
    33from itertools import count 
    44 
     
    342342 
    343343    # we are not a ComparableMixin, and therefore the webserver will be 
    344     # rebuilt every time we reconfig. 
     344    # rebuilt every time we reconfig. This is because WebStatus.putChild() 
     345    # makes it too difficult to tell whether two instances are the same or 
     346    # not (we'd have to do a recursive traversal of all children to discover 
     347    # all the changes). 
    345348 
    346349    def __init__(self, http_port=None, distrib_port=None, allowForce=False): 
     
    410413        self.template_values = {} 
    411414 
    412         # TODO: browsers will cache connections, and if we've recently 
    413         # reloaded the config file, a browser might still be talking to the 
    414         # previous Site, which will work for some things, but will break when 
    415         # they try to reach through our .parent attribute (usually via 
    416         # HtmlResource.getStatus(), which does 
    417         # request.site.buildbot_service.parent). I don't know of a good way 
    418         # to deal with this.. maybe the Site has some list of current 
    419         # connections which we can crawl through and terminate? 
     415        # keep track of cached connections so we can break them when we shut 
     416        # down. See ticket #102 for more details. 
     417        self.channels = weakref.WeakKeyDictionary() 
    420418 
    421419        if self.http_port is not None: 
     
    470468        """This behaves a lot like root.putChild() . """ 
    471469        self.childrenToBeAdded[name] = child_resource 
     470 
     471    def registerChannel(self, channel): 
     472        self.channels[channel] = 1 # weakrefs 
     473 
     474    def stopService(self): 
     475        for channel in self.channels: 
     476            try: 
     477                channel.transport.loseConnection() 
     478            except: 
     479                log.msg("WebStatus.stopService: error while disconnecting" 
     480                        " leftover clients") 
     481                log.err() 
     482        return service.MultiService.stopService(self) 
    472483 
    473484    def getStatus(self):