move closing and thread termination into finally block to not miss it when timed out