I don’t know what history books you have read but slavery was not on it’s way out. The southern slave owners precipitated a war to protect a perceived threat to their “property”. Slaves were being used in some of the factories in the south. Without the civil war slavery would probably have lasted well into the 20th century.
You can't have a thriving economy if nobody buys your product.
And many plantation owners were coming to realize that freed employees, allowed to work for you and also for their own families, tended to be more productive than people owned as property. Manumission became more common.
But the northern interests didn't want competition. And a consequence was that the South... which would have given up slavery sooner than later... instead hunkered down and said "SCREW YOU!"
Slavery could have ended by virtue of the free market. Instead the matter was forced at the point of a gun. Can't really blame anyone for responding in kind, if their homes and their families are threatened.