Resolve a set of race conditions in logging and attaching code Upstream-commit: 5eca7f7c5d7678f6548cd7d90199d67ce98d4c98 Component: engine