I'm a serial character killer. When I was younger almost every story I ever wrote ended with everybody important dying (surprise ending!) and while I admit, that was very, VERY stupid to end every story that way, I had a great English teacher in high school who set me straight about it.
He told me that there's nothing wrong with killing a main character, but if the death is meaningless and done for shock value alone, it's empty and not satisfactory for your readers. There has to be something to the death that makes it impactful, even if you upset some of your audience, it isn't as bad as just killing someone without any reason to do so. I would kill off an MC even today but, I recognize that there has to be something to their death, rather than it just happening out of the blue.
I think that, even readers who are upset by the death, can come around and see the narrative value in it. (Or heroic value, if that's what you're going for). 