What is going on in the end when Ivan Ilych has a realization and sees that flash of light? A whole lot, and it's worth asking questions about all of it.
What causes the light and Ivan's great realization? One minute he's suffering and then suddenly he's struck by a force in the chest and side and sees a light all around him. At the same time it becomes harder for him to breathe. It doesn't look like Ivan himself brings that about. What he apparently has to do is accept that his life was wrong, but that happens after he's struck and filled by the light, doesn't it? There are several questions to keep in mind:
Once he's already been flooded by the light, Ivan admits that his whole life was wrong, and asks what the right way to live would have been. He also feels confident that he must be able to "rectify" his life – make things right – somehow. But what does he mean by this? In what way was his life "wrong," and what would it mean for it to be "right"?
It seems like you can speak of the "wrongness" of Ivan's life in several ways. First, Ivan's life was definitely unhappy – he's been aware of that for a while. It also seems to have been meaningless; Ivan's life doesn't seem to have had any purpose. But then, thinking back to Chapter 9, there's also that language of "judgment" from God. Ivan's life hasn't been the life he's supposed to live according to God. God meant him to live some way, and Ivan messed it up. Whether or not Ivan thinks this has consequences for him after death is never said; once he sees the light, it doesn't seem that Ivan fears what will happen to him.
It's probably because Ivan didn't live as he was meant to that his life felt meaningless and was unhappy. What does it even mean that Ivan's life was "meaningless" anyway? What kind of meaning or purpose should his life have had that it didn't? Could there be any satisfying meaning or purpose other than the purpose God had for him, the way God intended him to live? (Consider that an open question. Though it's worth noting that Tolstoy himself would probably say no).
Given all of that, then, what is the "right" thing that Ivan's life lacked? That's what Ivan himself asks, and though the narrator doesn't respond, the timing of the narrative is revealing. Just when Ivan asks that question, he notices Vasya kissing his hand, and feels sorry for his son. Then he feels sorry for his wife.
He sees his son's compassion, and feels compassion within himself for the first time. Compassion is the answer. That's at least how it looks. And Ivan's whole life was certainly devoid of that. It was almost completely self-focused. Even in his illness, Ivan just felt sorry for himself, never for the people around him who might be suffering with him. Now the opposite is true.
That's a good question to ask yourself. It seems that Ivan rectifies his life by dying. He finds that he wants to die now, not so much to put an end to his own sufferings, but to end the suffering of his family. His death itself can be seen as an act of compassion – possibly his first one. Well, maybe his second, since he also tries to set things right by asking forgiveness from his wife and son (and, implicitly, from God). But it's his death that's the big deal. You might even say his death is what gives his whole life a meaning, even if it's at the last minute.
Not directly, but given that Ivan appears to be bathed in the light of God, it's hard not to get that sense. The ending of the Ivan Ilych feels triumphant, and happy. If Ivan had all of those wonderful realizations and then winked out of existence, would it still? If Tolstoy is implying that Ivan will experience a future afterlife, you can look at Ivan's redemption and bodily death as the beginning of his spiritual life.
Does it seem like God comes out of nowhere and saves the day at the last minute? There's actually a term for that – deus ex machina an old Latin phrase used to describe the endings of certain Greek tragedies. (The Latin literally means "God out of the machine," with "machine" meaning the independently moving plot that God enters from the outside). It refers to just this kind of ending, one in which everything looks so hopeless and incapable of resolution that all the author can do is bring God in to make everything right. The term is often used in a negative light, because something feels a little too easy about that kind of ending.
Does the ending of The Death of Ivan Ilych feel that way? If you think so, you certainly wouldn't be the first. Especially if you don't share Tolstoy's religious perspective, it can be a dissatisfying ending to an otherwise powerful story. The question is, would another ending have been satisfying? Tolstoy would probably say no – without God, there could be no satisfying resolution to life.