• Fabrice Bellet's avatar
    discovery: fix asynchronous agent refreshes pruning · e7b0b786
    Fabrice Bellet authored
    Asynchronous refreshes pruning may occur when the agent async close
    function is called, but also when a stream is closed. A flag
    'discarding' is used in the CandidateRefresh object to determine
    if a refresh is already on the way to be asynchronously freed. A refresh
    definitely freed is removed from agent refresh_list.
    
    When the agent async close function is called, it is passed a user
    callback that will be invoked when all refreshes have been freed.
    
    This is not exactly how things work currently, because right now, the
    callback function is also invoked when all CandidateRefresh objects have
    the discarding flag set, with the test 'data->items_to_free==0'. In that
    case, clearly not all refreshes have been freed, as some are still there
    in the refresh_list with the discarding flag set.
    
    This is probably not what the user expects from the function
    nice_agent_close_async(), where the callback is supposed to be invoked
    after all refreshes have been freed: and including those asynchronously
    pruned by nice_prune_stream_async().
    
    This patch adds a supplementary timeout when closing the agent async,
    that waits until the agent refresh list becomes empty.
    e7b0b786
agent.c 222 KB