Skip to content

Fix the data race when shutting down dns_adb

Ondřej Surý requested to merge 2978-fix-data-race-in-adb.c into main

When dns_adb is shutting down, first the adb->shutting_down flag is set and then task is created that runs shutdown_stage2() that sets the shutdown flag on names and entries. However, when dns_adb_createfind() is called, only the individual shutdown flags are being checked, and the global adb->shutting_down flag was not checked. Because of that it was possible for a different thread to slip in and create new find between the dns_adb_shutdown() and dns_adb_detach(), but before the shutdown_stage2() task is complete. This was detected by ThreadSanitizer as data race because the zonetable might have been already detached by dns_view shutdown process and simultaneously accessed by dns_adb_createfind().

This commit converts the adb->shutting_down to atomic_bool to prevent the global adb lock when creating the find.

Closes #2978 (closed)

Merge request reports