Fix race condition where message sent is inserted multiple times.

Change-Id: Ie52512a3e9aef86f144b8a19bcaf47b562b907e2