Fix a race condition which would sporadically result in duplicate messages