I do believe I have already fixed the bug I met before.
I have found that must close the pipe which is no use for anything.
So close the pipe handler as possibly as I can.