It may be that this person is actually struggling desperately in some way to come to terms with their feelings. The ‘racist’ aspect of their attack may be a way of sidestepping some other issue, or focusing their own muddle on someone close. The phrase ‘we always hurt the one we love’, is not a cliche, more of a sad truth. Playing together, working or becoming friends means boundaries are lowered. Can you find a way to approach this person directly to ask them about their behaviour?
Specifically, to enquire without accusation. For instance: “How come you are behaving this way towards me/someone?”. Don’t ask ‘why?’, it is an almost unanswerable question. Try the ‘how come’, or ‘how did you decide to’ behave/treat/expresss yourself… This might help to defuse the situation, the lack of accusation provides level ground for finding out more useful information.
We all have reasons for our behaviours. Not excuses, but personal truths. Each of us is culpable when we behave in ways that cause pain or concern. Asking for someone’s truth, permitting them to express that, without judging or looking for excuses can often help provide new, more solid communication. It may be that both of you could learn something helpful, which might strengthen the friendship. Or, at least find that it is time to move on to new friendships with less judgemental people. Good luck.