abyss7/dist-clang

clangd does not correctly exit on SIGTERM and SIGINT in most situations

Closed this issue · 2 comments

The cause is the following:

  1. Upon receiving a signal, the main thread is joining all the worker threads it has created.
  2. File cache has "Cache Resetter Worker" (https://github.com/abyss7/dist-clang/blob/master/src/cache/file_cache.cc#L108), which uses simple thread sleeps without any synchronisation (https://github.com/abyss7/dist-clang/blob/master/src/cache/file_cache.cc#L104).
  3. By default, if not overriden in config, sleep duration for this resetter thread is 600 seconds (https://github.com/abyss7/dist-clang/blob/master/src/daemon/configuration.proto#L31).
  4. As a result, clangd only exits 10 minutes after receiving termination signal. supervisorctl and other process management tools usually only wait a few seconds before sending SIGKILL, thus clangd always gets killed by this signal and does not exit gracefully.

Tried to fix that in #59

@abyss7 , probably, condition variables and wait_for should be more generic approach to achieve proper shutdown of worker threads which include periodic sleep, but I'm not sure whether it is really needed. What do you think?

Fixed in #59