Skip to content
Snippets Groups Projects
  • Nikolay Shirokovskiy's avatar
    99de5b74
    app: fix crash on logrotate and immediate exit · 99de5b74
    Nikolay Shirokovskiy authored
    `say_logrotate` does not rotate logs synchronously. It posts tasks to
    coio which executes them in it's pool thread. On application exit we
    destroy logs calling `log_destroy`. This function waits for rotate task
    to finish because if it will free resources immediately then unfinished
    rotate task can have use-after-free issues. Waiting crashes because at
    this moment event loop is not running which is required for
    `fiber_cond_wait` to work.
    
    Note that if there is no crash then we will hang forever waiting in
    `log_destroy` because event loop is not running and
    `log_rotate_async_cb` will never be executed.
    
    Let's use mutexes and conditions instead. It solves both problems with
    crash and hang. Thanks Vladimir Davydov for idea.
    
    Fixes #4450
    
    NO_DOC=bugfix
    
    (cherry picked from commit eed09192)
    99de5b74
    History
    app: fix crash on logrotate and immediate exit
    Nikolay Shirokovskiy authored
    `say_logrotate` does not rotate logs synchronously. It posts tasks to
    coio which executes them in it's pool thread. On application exit we
    destroy logs calling `log_destroy`. This function waits for rotate task
    to finish because if it will free resources immediately then unfinished
    rotate task can have use-after-free issues. Waiting crashes because at
    this moment event loop is not running which is required for
    `fiber_cond_wait` to work.
    
    Note that if there is no crash then we will hang forever waiting in
    `log_destroy` because event loop is not running and
    `log_rotate_async_cb` will never be executed.
    
    Let's use mutexes and conditions instead. It solves both problems with
    crash and hang. Thanks Vladimir Davydov for idea.
    
    Fixes #4450
    
    NO_DOC=bugfix
    
    (cherry picked from commit eed09192)