couchbase / couchbase-lite-ios

Lightweight, embedded, syncable NoSQL database engine for iOS and MacOS apps.
Apache License 2.0
1.63k stars 297 forks source link

Getting Warning Unparseable JSON for documents with valid json #978

Closed sellingsolutions closed 8 years ago

sellingsolutions commented 9 years ago

I'm running CBL 1.1.1 and SG 1.1.1

I ran the failing document through json lint and it comes back as valid.

This comes together with: CBL_Puller[...] failed to write {defect_2015-07-01t12_11_30_brf_linabergshojden_A3F09353-5B7E-4E4B-BA38-A23332A5920A #12-043a5f5fc9f5088a318a2f65373f935b}: status=590 2015-11-12 00:42:40.589 iSpect[34059:4560037] Replication: CBL_Puller[...] took 302.219 sec; error=Error Domain=CBLHTTP Code=500 "500 Database error!" UserInfo=0xc8719350 {NSLocalizedFailureReason=Database error!, NSLocalizedDescription=500 Database error!}

And eventually leads to a crash with the message: malloc: * mach_vm_map(size=1048576) failed (error code=3) * error: can't allocate region securely

Here's the bt all: http://pastebin.com/YtmiZHq0

snej commented 9 years ago

Please post the exact warning message and the document's JSON. (If the JSON is big, you can put it in a gist or something.)

From the backtrace, it looks like the line that triggered the crash is in your code — it's a call to an NSString category method -containsStringCaseSensitive: at NSString+Contains.m:18.

snej commented 9 years ago

I think I recall some cases where NSJSONSerialization is unable to parse JSON. I'm pretty sure they involve numbers — possibly scientific-notation numbers whose exponent is larger than a double can handle (that's about 1e±300, I think.) The JSON spec says nothing about the maximum size of a number, but most languages can't represent arbitrarily large numbers.

zgramana commented 9 years ago

@sellingsolutions can you provide some examples of problematic JSON?

sellingsolutions commented 9 years ago

I'm pretty sure it's what Jens suspects, I do recall getting warnings in the sg log about doubles not being stored properly. I'll look into doing some migrations to remove big doubles

snej commented 8 years ago

What exactly was the warning that you got? You only paraphrase it, in the title. I'd like to know what source file/line it came from.