Fixed duplicate names race condition

to be backported to stable
fixes #614