[obsoleted]TTL does not work in some scenario


#1

It seems that value expiration does not properly works in some scenario.
I have written small example to illustrate such behavior:
Second value never expires after 5sec of program execution.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Couchbase;
using Couchbase.IO;

namespace CBTroubleShoot
{
class Program
{
static void Main(string[] args)
{

        string key1 = "key1";
        string key2 = "key2";
        string val1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
        string val2 = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?";

        int hash1 = val1.GetHashCode();
        int hash2 = val2.GetHashCode();
        ClusterHelper.Initialize("couchbaseClients/couchbase");
        var b = ClusterHelper.GetBucket("sessionState");
       
        object o=new object();
        b.Remove(key1);
        b.Remove(key2);
        
        Task[] taskArray = new Task[100];

        for (int ii = 0; ii < 1000; ii++)
        {

            for (int i = 0; i < taskArray.Length; i++)
            {
                taskArray[i] = Task.Factory.StartNew((Object obj) =>
                {
                    var v2 = b.Get<string>(key2);
                    var v1 = b.Get<string>(key1);

                    if (v2.Status == ResponseStatus.KeyNotFound && v1.Status == ResponseStatus.KeyNotFound)
                    {
                            var w1 = b.Upsert(key1, val1, TimeSpan.FromSeconds(5));
                            if (!w1.Success) Console.WriteLine(w1.Status);
                            var w2 = b.Upsert(key2, val2, TimeSpan.FromSeconds(5));
                            if (w2.Success) Console.WriteLine(w1.Status);
                    }

                    if (!v1.Success)
                    {
                        Console.WriteLine(v1.Status);
                        }
                    else
                    {
                        Console.WriteLine(v1.Value.Length);
                    }
                    if (!v2.Success)
                    {
                        Console.WriteLine(v2.Status);
                    }
                    else
                    {
                        Console.WriteLine(v2.Value.Length);
                    }

                    if (v1.Success && v2.Success)
                    {
                        if (v1.Value.GetHashCode() != hash1) Console.WriteLine(v1.Status);
                        if (v2.Value.GetHashCode() != hash2) Console.WriteLine(v1.Status);
                    }
                },
                    i);
            }
            Task.WaitAll(taskArray);

        }


    }
}

}

Server version: Version: 3.0.2-1603 Enterprise Edition (build-1603) on windows server 2012 R2
Client version: 2.1.1

Please find log attached