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

Redis cache InvalidOperationException: Reading is not allowed after reader was completed #342

Open
ashuthinks opened this issue Oct 15, 2020 · 2 comments

Comments

@ashuthinks
Copy link

ashuthinks commented Oct 15, 2020

I have one webjob that is continously inserting data into redis I have another time trigger function to read data from the same redis cache after every 5 minutes.

  // redis cache
    public static NewtonsoftSerializer newSerializer = new NewtonsoftSerializer();
    public static SinglePoolRedisCacheConnectionPoolManager newSpRedisCacheConnectionPoolMgr = new SinglePoolRedisCacheConnectionPoolManager(ConfigurationManager.AppSettings["redisConnectionString"]);
    public static RedisConfiguration newRedisConfiguration = new RedisConfiguration();
    public static IRedisDatabase newCacheclient = new RedisCacheClient(newSpRedisCacheConnectionPoolMgr, newSerializer, newRedisConfiguration).Db0;

public static void ProcessData([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer)
{
var newCacheclient = new RedisCacheClient(Program.spRedisCacheConnectionPoolMgr, Program.serializer, Program.redisConfiguration).Db0;

        var cachedData = newCacheclient.GetAsync<List<MyObject>>("mydata").Result;

after executing 10-15minutes I'm getting below error from time trigger function .anyone know how to tackle this?

InvalidOperationException: Reading is not allowed after reader was completed.

nuget version details - https://i.stack.imgur.com/LWSss.png

Error Stack - Inner Exception 1:

InvalidOperationException: Reading is not allowed after reader was completed.

at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at MyData.Functions.ExecuteTrade(TimerInfo myTimer) in C:\Users\\Functions.cs:line 27 at Microsoft.Azure.WebJobs.Host.Executors.VoidMethodInvoker1.InvokeAsync(TReflected instance, Object[] arguments)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.d__0.MoveNext()

at System.IO.Pipelines.ThrowHelper.ThrowInvalidOperationException_NoReadingAllowed()
at System.IO.Pipelines.Pipe.AdvanceReader(SequencePosition& consumed, SequencePosition& examined)
at System.IO.Pipelines.Pipe.DefaultPipeReader.AdvanceTo(SequencePosition consumed, SequencePosition examined)
at StackExchange.Redis.PhysicalConnection.d__110.MoveNext() in /_/src/StackExchange.Redis/PhysicalConnection.cs:line 1495
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at StackExchange.Redis.Extensions.Core.Implementations.RedisDatabase.d__14`1.MoveNext()

@lookingcloudy
Copy link

Seems to be a common error.

@imperugo
Copy link
Owner

Hi @ashuthinks

first of all thanks for using the library.
Looking at your code I see different things that are not correct:

This is wrong

var cachedData = newCacheclient.GetAsync<List<MyObject>>("mydata").Result;

use the async method instead or, if you can't use the async method, please use this approach

var cachedData = newCacheclient.GetAsync<List<MyObject>>("mydata").GetAwaiter().GetResult();

Moreover, the library you are using is very old. You are using the 6.3.5 that was released on 9/1/2020 now we are on 10.2.0, so please update to the latest version.

@lookingcloudy what do you mean with "Seems to be a common error." ? Do you have the same issue?

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

No branches or pull requests

3 participants