fixing sync hanging in pulpv2

based off this commit 4c8a60b81564474cc2c36c245a9e2897525811f6
but with a slightly different algorithm
Merge pull request #1474 from jlsherrill/pulpv2

fixing sync hanging in pulpv2