Avoid replication task crashes by imporoving timeout handling. Closes COUCHDB-597. Patch by Randall Leeds.