Cherry-pick the detach patch from upstream