One of the best ways of handling this is to use the 3 breaths technique. When you feel you are about to be drawn into the same behavior as the customer, take an immediate pause and breath in and exhale 3 times. The longer the breaths the better.
Research has shown that this will immediately give you a method of distancing yourself from a customer's frustration/anger/animosity.
Always remember. Your job is to serve and help solve the customer's problem. Not fight with him.
The term customer service has a meaning. Serve the customer.