Section 17. A person indebted to a bank may, when proceeded against for the collection of such indebtedness or for the enforcement of any security therefor, set off or recoup the amount of a deposit in such bank held and owned by that person at the time of the commencement of such proceeding; provided, however, that if a proceeding in equity has been commenced to restrain the bank from doing its actual business, or if possession of such bank has been taken over by the commissioner, pursuant to section 22 of chapter 167, or as otherwise provided by law, no deposit shall be so set off or recouped by any such person unless the person held and owned the deposit on the date of the commencement of such proceeding or of possession so taken, and the right of set off or recoupment shall be determined as of such date whether the indebtedness of the depositor, or the deposit, is then due or payable or becomes due or payable at a later date. Any indebtedness against which a deposit is permitted to be set off or recouped as aforesaid may be secured or unsecured. Section 3 of chapter 232 shall not apply to a set off under this section; provided, however, that any party to a joint account may set off the joint deposit against the individual's debt to such bank. Notwithstanding the foregoing, a judgment shall not be rendered against such bank in favor of the defendant for any balance found due from it if a proceeding in equity has been commenced against the bank or possession thereof has been taken as aforesaid. The word ''deposit'', as used in this section, shall include interest due thereon.