Error replicating to .NET CB Lite DB from Sync Gateway

Not sure what I’m doing wrong here, but I’m getting an exception thrown randomly when I try and sync through the sync gateway to my new Couchbase Lite database. During the replication process, I get an exception (only every 5k-10k rows, or about every 3-4 minutes):

{"Object reference not set to an instance of an object."}
[System.NullReferenceException]: {"Object reference not set to an instance of an object."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2147467261
InnerException: null
Message: "Object reference not set to an instance of an object."
Source: "Couchbase.Lite"
StackTrace: "   at Couchbase.Lite.Replicator.BulkDownloader.ExecuteRequest(HttpClient httpClient, HttpRequestMessage request)"
TargetSite: {Void ExecuteRequest(System.Net.Http.HttpClient, System.Net.Http.HttpRequestMessage)}

All of the records are actually loaded into memory as far as I can tell (I have an event handler for the replication.Pull event that logs them to a file/console). It takes about 15 minutes to run, but once these are loaded into memory, another error occurs. In the end, nothing get’s written to the local lite database.

BulkDownloader: Unhandled Exception at Line 129 or 130
System.Threading.Tasks.TaskCanceledException: A task was canceled. Replication:  Progress: set error = System.Threading.Tasks.TaskCanceledException: A task was canceled. BulkDownloader: ExecuteRequest Exception: System.NullReferenceException: Object reference not set to an instance of an object. at couchbase.Lite.Replicator.BulkDownloader.ExecuteRequest(HttpClient httpClient, HttpRequestMessage request) Replication:  Progress: set error = System.NullReferenceException: Object reference not set to an instance of an object.
   at Couchbase.Lite.Replicator.BulkDownloader.ExecuteRequest(HttpClient httpClient, HttpRequestMessage request)

or

BulkDownloader
Response task timed out: System.Threading.Tasks.Task`1[System.Net.Http.HttpResponseMessage], Couchbase.Lite.Util.SingleThreadTaskScheduler BulkDownloader: ExecuteRequest Exception:
[HttpResponseException: StatusCode = RequestTimeout] Replication:  Progress: set error =
[HttpResponseException: StatusCode = RequestTimeout] BulkDownloader: ExecuteRequest Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Couchbase.Lite.Replicator.BulkDownloader.ExecuteRequest(HttpClient httpClient, HttpRequestMessage request) Replication:  Progress: set error = System.NullReferenceException: Object reference not set to an instance of an object. at Couchbase.Lite.Replicator.BulkDownloader.ExecuteRequest(HttpClient httpClient, HttpRequestMessage request)

Detail:
I have a bucket with ~200k entries. Sync gateway is setup with a shadow bucket that is getting served out. I believe that is working because the shadow and original buckets match the document count and I don’t see errors when I run the SG verbosely. I can query the sync gateway using the REST API and haven’t had issues.

I’m running SyncGateway 1.0.3-81, Couchbase Lite from NuGet v1.0.0, Couchbase Server 3.0.1 EE.

Well that’s not supposed to happen. :wink: It looks like the transient error handler was not able to successfully retry the bulk download before the entire request timed out. Unfortunately, it looks like I didn’t correctly catch the TaskCanceledException resulting from that timeout.

I’ve opened a github issue so that we can track this. I’m on holiday leave, so it may be a week or two before I get a chance to look at this in greater depth. Any updates on progress will be made on that issue.

Thanks for reporting!

The message “Object not set to instance of Object” means that you are trying to use an object which has not been initialized. That is, you either set it to null, or you never set it to anything at all. The runtime throwing a NullReferenceException always means the same thing: you are trying to use a reference. The reference is not initialized (or it was initialized, but is no longer initialized). This points to one of the following:

Your code declared an object variable, but it did not initialize it (create an instance or ‘instantiate’ it)

Something which your code assumed would initialize an object, did not

Possibly, other code prematurely invalidated an object still in use.

More about…NullReferenceException

Bang