BZ-1048245 - Error when auto deploying a unit after server restart due to: java.lang.IllegalArgumentException: number of transferred bytes cannot be negative

(cherry picked from commit 50bb9fd14768aa8c5ec33e267cea3036f854fdd1)