Skip to content
Snippets Groups Projects
  • Andy Green's avatar
    ac3bd36c
    vhost_destroy: use vhost wsi reference counting to trigger destroy · ac3bd36c
    Andy Green authored
    This changes the vhost destroy flow to only hand off the listen
    socket if another vhost sharing it, and mark the vhost as
    being_destroyed.
    
    Each tsi calls lws_check_deferred_free() once a second, if it sees
    any vhost being_destroyed there, it closes all wsi on its tsi on
    the same vhost, one time.
    
    As the wsi on the vhost complete close (ie, after libuv async close
    if on libuv event loop), they decrement a reference count for all
    wsi open on the vhost.  The tsi who closes the last one then
    completes the destroy flow for the vhost itself... it's random
    which tsi completes the vhost destroy but since there are no
    wsi left on the vhost, and it holds the context lock, nothing
    can conflict.
    
    The advantage of this is that owning tsi do the close for wsi
    that are bound to the vhost under destruction, at a time when
    they are guaranteed to be idle for service, and they do it with
    both vhost and context locks owned, so no other service thread
    can conflict for stuff protected by those either.
    
    For the situation the user code may have allocations attached to
    the vhost, this adds args to lws_vhost_destroy() to allow destroying
    the user allocations just before the vhost is freed.
    ac3bd36c
    History
    vhost_destroy: use vhost wsi reference counting to trigger destroy
    Andy Green authored
    This changes the vhost destroy flow to only hand off the listen
    socket if another vhost sharing it, and mark the vhost as
    being_destroyed.
    
    Each tsi calls lws_check_deferred_free() once a second, if it sees
    any vhost being_destroyed there, it closes all wsi on its tsi on
    the same vhost, one time.
    
    As the wsi on the vhost complete close (ie, after libuv async close
    if on libuv event loop), they decrement a reference count for all
    wsi open on the vhost.  The tsi who closes the last one then
    completes the destroy flow for the vhost itself... it's random
    which tsi completes the vhost destroy but since there are no
    wsi left on the vhost, and it holds the context lock, nothing
    can conflict.
    
    The advantage of this is that owning tsi do the close for wsi
    that are bound to the vhost under destruction, at a time when
    they are guaranteed to be idle for service, and they do it with
    both vhost and context locks owned, so no other service thread
    can conflict for stuff protected by those either.
    
    For the situation the user code may have allocations attached to
    the vhost, this adds args to lws_vhost_destroy() to allow destroying
    the user allocations just before the vhost is freed.