Over the years we have had a few handlers loose their dogs to age and one to a genetic heart defect. ALL of those officers were badly shaken and distraught when their partners passes, especially when the one with the heart issue passed, it happened "on the job" and they ran lights & sirens to the vet's but were too late. These dogs live with their handlers nearly 24/7 they go home with them, interact with the family, BECOME family and the "It's only a dog" frame of mind really doesn't exist anymore. When the dog passes 'on duty' it's the same as one of your human partners, only you know that the dog was doing what it was trained to do, odds are what it loved to do ... work along side you. I'd be willing to bet the dogs do know what they are walking into. their instincts and senses are so much stronger than ours, but still they do it willingly because they do it for us, THEIR family to keep US safe, it's what they do.
I know of one K9 named Lurch (from the Addams Family) because he was so big. One night a vicious stray came onto the property and acted threatening around the handler's wife. Lurch immediately took off after the intruder, but unfortunately didn't stop once the intruder left the property and crossed the street, and Lurch was hit by a car. Many surgeries later, missing his tail, and half of his bowels and with no real strength in his hind legs Lurch STILL wanted to work and protect his family. He would lay around depressed (you could tell) until the handler would grab his collar and give him an aggressive command, such as "Watch him," "Hold him", or even better "Get him." With no power in his back legs the handler could easily hold Lurch back, but when the exercise was done, you could see a change in Lurch's demeanor, he was excited and you could tell he had fun. Lurch was put down shortly after because of the injuries, but you knew that dog would have knowingly died to save you, which in effect he did ... it just wasn't quick.