Race attach fix

Fixes #803