Skip to content

Reading record's TTL value is wrong #63

@anestorov

Description

@anestorov

I think there are 2 issues connected with reading TTL.

1. Reading record's ttl via getTtl() method always returns 1 when TTL is set to expire
2. Reading record's ttl via getTtl() method returns random big value like 3803929607 when TTL is set to never expire (-1)

Here is an example of the code

$key = new Key("test-ns", "test-set", "1234");
$rp = new ReadPolicy();
$record = $client->get($rp, $key, null);

$record->getTtl()

Problems seems to be in src/lib.rs - pub fn get_ttl(&self) -> Option<u32>

Abount the first issue I think the concept of TTL implemented in that function's body is wrong.
It considers TTL to be number of seconds since CITRUSLEAF_EPOCH but in fact it is not.
TTL in secs variable is the amount of seconds since the present moment when the record will expire.

Due to this conception misunderstanding all the code that adds it to CITRUSLEAF_EPOCH and compares it with the now time is not necesary. In fact the following check if expiration > now never gets true (with relatively small ttl withing a few years) and the functions always return (1 as u32).into();

Second issue is due to wrong comparison as NEVER_EXPIRE is not 0 but 0xFFFFFFFF. So when ttl = NEVER_EXPIRE it then actually goes to the second match and subsequently satisfy if expiration > now and efectively returns NEVER_EXPIRE + CITRUSLEAF_EPOCH - NOW. Additionally this method is supposed to return i32 in order for NEVER_EXPIRE (0xFFFFFFFF) be represented as -1

Later on I found that get_expiration method is also bad. I am making a pull request with the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions