Properly stop metric information gathering and sending on shutdown. Issue reported by AddressSanitizer. (cherry picked from commit e9c475d45f7fbe78d68e8d0cafe66b829acb6ce6)