Fix a bug when res.threads is undefined