CouchbaseNetClient is expiring things way too quickly


#1

My Coworker has exposed this issue.

The bug / fix is that the duration is placed in the milliseconds parameter of the TimeSpan constructor. This should be in the seconds parameter. This is highlighted in his notes, below.

This documentation tells you to use to specify expiration in seconds http://docs.couchbase.com/developer/dev-guide-3.0/doc-expiration.html
If you want an item to live for less than 30 days, you can provide a TTL in seconds or as Unix time.

So when I specify my Expiry as 2592000 = 30 days my doc is expiring in 41 minutes.

Turns out they are asking users to specify seconds but using it as milliseconds -
var result = Upsert(document.Id, document.Content, document.Cas, document.Expiry.ToTtl());

        {
            return ToTtl(new TimeSpan(0, 0, 0, 0, (int)duration));
        }```

https://github.com/couchbase/couchbase-net-client/blob/master/Src/Couchbase/Utils/TimeSpanExtensions.cs#L35

Timespan - https://msdn.microsoft.com/en-us/library/6c7z43tw%28v=vs.110%29.aspx

#2

@unhuman -

There is a discrepancy between the server documentation and the SDK documentation ( here too) regarding TTL. The SDK expects milliseconds to be passed in and it will handle the conversion specified in the server documentation to Unix time; this is for convenience. The reason the SDK uses milliseconds is because it’s a more standardized way of specifying a TTL than seconds from an API perspective.

Note that there are additional overloads (but none for Document), which take a TimeSpan as the TTL; for those methods it’s preferable over the overloads that take a unsigned int.

I opened up a ticket to address this here. Sorry for any confusion this may have caused.

-Jeff


#3

Thanks for the explanation. We’ve worked around it here.

If we’re using milliseconds, however, wouldn’t a long be a better implementation than a uint? uint cuts off at 24 days.


#4

Actually I believe uint is 49 days; agreed ulong would be better. The suggested work around is to use one of the overloads that takes a K/V pair and not a document and includes a TimeSpan for an expiry.

I created a ticket here to add a property to IDocument and/or change the Type to ulong: http://issues.couchbase.com/browse/NCBC-954. This would be a potentially breaking change, so it won’t likely be addressed until the next major release.

Thanks,

-Jeff