I would always advise writers to ensure that their contracts contain good reversion clauses.
Reversion clauses specify the circumstances under which the rights to publish a book will revert from the publisher to the author: they usually kick in once a book has been out of print, or is otherwise unavailable, for six months or so.
For a reversion clause to be invoked, it's common for the writer (or their agent) to have to request a reversion of rights, so writers must not rely on it happening automatically.
Even when there is no reversion clause in place, it is worth writers requesting the return of their rights once their books show no sales over a period of several months. Most publishers are quite happy to arrange this, so long as they are no longer making any sales on the title.