fix size may > consumed_size cause free_size cant contain the encoded data
add timer to ensure buf cleaned
fix consumed_size overflow and add some null check