Fix the memory leak issue when attaching large streams

See mikeal/request#898