Merge "Only detach shutdown thread if we attached it"