We've all seen author's darlings. Characters you know the author would never allow to die, no matter how ridiculous the odds. To me, the first question that should be posed is: is this necessarily bad? The answer is, of course (as with any 'necessarily' question), is no.
...For the most part, though, it's 'yes'. So why?
Take Eddings as our case study. Or rather, Eddings vs. Martin (which yes, sounds like some kind of SFF wrestling match). With Eddings, we know that nobody will die - or at least, none of the main protagonists. And why? Because they never have, and that's why, when one does, we don't believe it (and we're right, he's resurrected right afterwards. Talk about a cheat).
Now take a look at Martin. His protagonists are dropping like flies from book one. In fact, in SFF, we don't even use 'dropping like flies' any more - it's 'dropping like Starks'. And when his characters die now, we do believe it - in fact, we're worrying about which of our favourites will die next, and it takes the tension up in a way that Eddings never could.
But maybe I'm specifying 'death' as the only medium of punishment for those pesky protagonists too much now - so it's time to talk about pain. Body found floating by the docks... Okay, maybe not Abercrombie-pain, which is a little too grotesquely detailed for me, but you know what I mean. Protagonists don't need to die to suffer, and it's these trials and tribulations, the fact that protagonists can't always succeed and are in fact frequently doomed to failure that makes them interesting. It's one of the reasons I argue that Kvothe isn't a Mary Sue - because although we know he lives, we also know he lives transformed. And we know he failed, and became a much darker character for it. So I don't mean that your protagtonist necessarily has to die in book one to make me believe it, or be tense about it, when someone else dies in book six. But somebody does need to get hurt.
There are other reasons for not keeping your characters close: for one, drama. Sacrifice is important, and if characters can never suffer for what they do, it tells us that it isn't important. That they aren't making hard decisions, and that frequently they're just angsting about nothing (uh, take that, Eragon). Yes, Erikson's characters do frequently come back, but do they suffer? Do they make hard decisions? That';s a yes, by the way.
And now to get back to our overall answer: a no. You don't have to kill your protagonists, or even make them suffer that much - if you're writing early YA, or comic fantasy. But should you try to give them some consequences? Yes.
...Or at least, so goes my very subjective train of thought. What do you think? Comment and tell me below!