Ah mate that really sucks, I had that once during a raid, I was so sad after. Also, pretty sure you can claim for the M4 you lost if you want. IIRC someone had a refund request accepted for the same reason.
Yeah its pretty annoying with the demos stopping and recording again and the serious lag spikes that are caused.
I have a solution for this, when your about to raid or get raided type stop in console. This will stop recording the demo just incase it happens while you are being raided or raiding. When your finished you can type record "name of demo" (take out the quotation marks)
Hope you find this useful and im happy to help with anything.