TDI-28452:backport the TDI-28452 and TDI-30951 together on 5.4.