Fix thread affinity on errors