Fix race condition where message received is inserted multiple times.

Change-Id: I9655d11cc466aa100365c3f9d0bf0be736a4caa4