Have you tried this:
if (client) { client.setTimeout(5); ...
This hint from Federico helped in my project.