Fix bugs and stop threads when socket in disconnect state