pretty sure they can return the shares whenever they want, unless the lender of the shares demands their return, in which case they have to be returned at that time.
also, i think it's all pretty much mechanical, like when you place an order to sell short, the order processing involves finding a lender and securing those shares. and then if the lender sells their shares, that order involves automatically recalling their shares and the borrower is then automatically matched with another lender, etc.
at least for retail.