If a defendant in attachment for a debt not due, shall on or before the return-day thereof, execute and deliver to the officer serving the same, a bond, with two or more sufficient sureties, to be approved by said officers, payable to the plaintiff in attachment, in a penalty double the amount claimed by the plaintiff, conditioned to pay the said debt when it shall become payable and costs of the attachment, the said attachment shall be discharged thereby, and all the property attached shall be released to the defendant. The bond shall be delivered by the officer to the plaintiff. After the return of the attachment, the bond herein provided for may be given at any time before final judgment, and may be taken by the sheriff or officer by whom the attachment was served, in case any of the attached property remains in his hands, or by the clerk of the court in which the attachment is pending.