Bug fix: Check thread status when closing TCP.
Merge branch 'feature/bugfix'