Google's Gmail has the feature that allows you to Un-send an email within a few seconds after hitting send. I can of course guess on how this works but I've never been able to find any specific details on how this might be accomplished.
My theory
Basically I imagine the way this works is that Google is able to track the state or status of an email coming into their servers and/or being delivered to the recipient. An email sent through Gmail would initially be in some kind of "uploading" state and the Gmail browser client would continually read the state of the email until it changes to "unretrievable" at which point the message changes to "Sent" and the undo option disappears.
My main question around this is how do they prevent race conditions?
For example what if I click on the Un-send
button milliseconds before the status changes to unretrievable and my Un-send
packet doesn't reach the server fast enough.
What kind of reversal process would occur?
How does Gmail's Un-send feature work and specifically how do they prevent race conditions?