There are a number of factors at play here and I do wonder how it will turn out in the end. If we look at Putin's stated agenda at the start of his war, he intended to push the NATO troops farther from Russia's borders, remove "nazis" from Ukraine, and restore normal relations between the two countries, i.e. make Ukraine economically and politically dependent on Russia at the most liberal or annex it completely. In real-world terms, he has already lost the war.
He was forced to withdraw from the Northern offensive so no quick decapitation of the Ukrainian government, followed by the rapid installation of a puppet government in love with Russia. The Ukrainian army and people he encountered were not the people he encountered in 2014 when he started this little adventure in imperialism. They have fought him hard from the start. Even in areas under his control, partisan activity has started and continues to grow stronger. There is partisan activity in Kherson, Melitopol, and around Mariupol. In the north during the current offensive, partisans have played an important role. So, Putin needs to tie down the territory he is occupying with large numbers of troops. Troops he needs elsewhere.
He has actually weakened Russia's position in the world. He has a brand-new huge border with NATO in Scandanavia that he did not have before. He has NATO troops and equipment in Poland and the Baltic States that were not present there previously. He has revitalized NATO as well. Some of the older members, including the US who were questioning its relevance in the current world woke up quickly. So, Putin has done more to help NATO than anyone in recent decades. In addition, his imperialistic jaunt into Ukraine conclusively demonstrated that the massive army of the USSR is gone and has been replaced by a Russian army filled with corruption, and obsolete, poorly maintained equipment, and poorly trained troops. At the same time, he has been using up equipment, ammo, and troops at a rapid clip, all while the NATO boogieman sits there on the other side of his border. To the Russian generals who have been raised since birth to fear invasion from the West, that has to be the stuff of nightmares.
Then there is the economic side of things. Putin has been working hard to turn Russia into a pariah state with no small success. Those oil/gas sales to India and China, while nice, are not anywhere near the volume of his sales to the West, especially the EU. He can cook the books for a while but he is going to pay the price for doing so. Not to mention that India and China are not paying the market rate for the oil/gas they are buying. It is steeply discounted. Chinese sources have said as much as fifty percent. And while he has the EU over a gas barrel at the moment, they are moving quickly to reduce their reliance on Russian sources of energy.
Both of these countries have aging populations with a smaller-than-average pool of possible able-bodied troops. The Ukrainians are highly motivated and have been from the start but there are only 48 million of them compared to Russia's 144 million. The Russians have not been and so far, Putin has refrained from recruiting much in the west of the country around Moscow & St Petersburg. The majority of the troops fighting and dying in Ukraine have been from the eastern part of the federation. They are from impoverished areas and frankly, the "white" Russians in the west of the country don't care how many of those folks die. But sooner or later both sides will run out of troops. Ukraine has a third of the population of Russia.
The question here is what happens. The problem for Ukraine is that Russia and Putin are in a very bad situation. One that a smart person would wiggle out of by simply declaring they had won and now that they had grabbed some land, they are leaving. But the Russian mentality is twisted here. They really do consider themselves far superior to the Ukrainians in every aspect. The idea of the Ukrainians beating them in a stand-up war is simply unacceptable. That is why recently on their own media the talking heads are claiming that the troops in the current Ukrainian offensive are actually NATO troops, including [gasp] Negroes, not Ukrainians!
So, how does this end? With a bloody war of attrition in which Putin finally overcomes Ukraine by simply having a few more men than the Ukrainians have while exhausting his country to the point it fractures and falls apart? Or will the Russian military, political, and business elites finally see the foolishness of following that path to its logical conclusion? One at the end of which, China and the US will simply split up the remains of the old Russian empire. Hence my reference to Putin's Swan Song moment.
Is the day coming when the people of Russia awaken to hearing the music of Swan Lake on the radio as their televisions show the ballet itself, all on repeat until some once news announcer comes on line to tell them that Putin has tragically suffered a catastrophic stroke and dies or did not die but has resigned and gone to his dacha in Soichi? It definitely could happen.