Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PutIfAbsent with ForceReturnValue=true hangs indefinitely for non-existent keys #47

Open
ppetrovt opened this issue Mar 7, 2024 · 4 comments · May be fixed by #48
Open

PutIfAbsent with ForceReturnValue=true hangs indefinitely for non-existent keys #47

ppetrovt opened this issue Mar 7, 2024 · 4 comments · May be fixed by #48
Assignees

Comments

@ppetrovt
Copy link

ppetrovt commented Mar 7, 2024

When utilizing the PutIfAbsent method with the parameter ForceReturnValue set to true, an unexpected behavior occurs when the key doesn't exist. Specifically, the application hangs indefinitely instead of returning the expected result. It's noteworthy that the issue doesn't manifest when ForceReturnValue is set to false.

Upon further investigation, it's observed that even though the application appears to hang, subsequent restarts reveal that the value has indeed been added to the cache. However, the application fails to receive this result.

Expected Behavior:

The expected behavior of the PutIfAbsent method with ForceReturnValue set to true is to return the previous value associated with the key, which, in this scenario, should be null since the key doesn't exist prior to the operation.

Steps to Reproduce:

  1. Call the PutIfAbsent method with ForceReturnValue=true.
  2. Provide a key that doesn't exist in the cache.
  3. Observe that the application hangs indefinitely instead of returning the expected result.
@rigazilla rigazilla self-assigned this Mar 8, 2024
rigazilla added a commit to rigazilla/Infinispan.Hotrod.Core that referenced this issue Mar 8, 2024
@rigazilla rigazilla linked a pull request Mar 8, 2024 that will close this issue
@rigazilla
Copy link
Collaborator

@ppetrovt thanks for reporting this.

Could you try a run with #48 applied?

@ppetrovt
Copy link
Author

ppetrovt commented Mar 9, 2024

@rigazilla thanks for the fast response, it is fixed, but now the next request hangs

Example code

using Infinispan.Hotrod.Core;
using System;

var ispnCluster = new InfinispanDG
{
	User = "admin",
	Password = "admin",
	AuthMech = "DIGEST-MD5",
	Version = 0x1f,
	ClientIntelligence = 0x03,
	ForceReturnValue = true,
};
ispnCluster.AddHost("localhost", 11222);

System.Threading.Thread.Sleep(1000);

var cache = ispnCluster.NewCache(new StringMarshaller(), new StringMarshaller(), "test1");
string key = Guid.NewGuid().ToString();

string result = await cache.PutIfAbsent(key, "value1").WaitAsync(TimeSpan.FromSeconds(30));
Console.WriteLine("Result is: " + result);

string getResult = await cache.Get(key).WaitAsync(TimeSpan.FromSeconds(30));
Console.WriteLine("Get Result is: " + getResult);

Expected Result

Result is:
Get Result is: value1

Actual Result

Result is:
Unhandled exception. System.TimeoutException: The operation has timed out.

I am testing both distributed and replicated caches, both transactional.

@rigazilla
Copy link
Collaborator

@ppetrovt, unfortunately C# client doesn't support transactions yet.
... though your code should work, can you post the cache configuration?

@ppetrovt
Copy link
Author

@rigazilla I have tried many configurations; here are some of them.

{
  "ProfileData": {
    "replicated-cache": {
      "mode": "ASYNC",
      "statistics": true,
      "encoding": {
        "media-type": "application/json"
      }
    }
  }
}
{
  "ProfileDataTransactional": {
    "replicated-cache": {
      "mode": "SYNC",
      "statistics": true,
      "encoding": {
        "media-type": "application/json"
      },
      "locking": {
        "isolation": "REPEATABLE_READ"
      },
      "transaction": {
        "mode": "NON_XA",
        "locking": "OPTIMISTIC"
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants