Backported message loss fix from master