Fix a more or less rare dead lock.

The issue is caused when the node tree is modified after we detect the need
to wait for a node tree modification and before the proper wait.