Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(persistent-stream): reconnect for timeouts #23

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions scripts/persistent-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,23 @@ PersistentStream.prototype._shouldReconnect = function (err) {
return true;

default:
// We sometimes get "Invalid JSON" errors when listening to CouchDB _db_updates feed and the
// CouchDB instance is restarted.
//

// TODO: JSONStream throws errors like err.message='Error: Unexpected STRING(" }, { ") in state
// COMMA'. Should we submit a PR that instead generates something like an InvalidJSONError?
//
// - emfile => occurs randomly when many simultaenous connections
// - socket hang up => occurs randomly when many simultaenous connections
// - HPE_INVALID_CHUNK_SIZE => occurs randomly when many simultaenous connections
return /Invalid JSON|emfile|socket hang up|HPE_INVALID_CHUNK_SIZE/.test(err.message);
return new RegExp([
// We sometimes get "Invalid JSON" errors when listening to CouchDB _db_updates feed and the
// CouchDB instance is restarted.
'Invalid JSON',

// Occurs randomly when many simultaenous connections
'emfile',
'socket hang up',
'HPE_INVALID_CHUNK_SIZE',

// Occurs randomly even when there is a relatively small amount of data, e.g. "The request
// could not be processed in a reasonable amount of time"
'timeout'
].join('|'), 'i').test(err.message);
}
};

Expand Down