Indeed, SpaceX was indeed almost bankrupt. It only succeeded because the last attempt to launch and land a reusable rocket got them a massive cash injection from NASA. But if that launch had failed like the ones before it, that would have been the end of SpaceX.