BeetleX.Redis
BeetleX.Redis copied to clipboard
Slate state when HttpClient reconnects
When a connection is interrupted, the ping
thread marks the RedisHost as unavailable. But, when the connection is restored, it does not update the Available property. It seems that the AsyncTcpClient recovers itself, marking the client as Connected, but the Available property is not updated.
Note that the TcpClient will have the IsConnected property as true
, but the Available property will remain as false
https://github.com/beetlex-io/BeetleX.Redis/blob/df7fcaff52a012b783f6583327ab788af27e2756/src/RedisHost.cs#L94-L126
Steps to reproduce:
- Host a local redis server
- Make a call (in my case, from an asp.net core controller), e.g. INFO. Everything works as expected.
- Now, shutdown the Redis instance
- Make the call again. It should throw an exception and the host marked as
Available = false
- Start the Redis server again.
- Make the same call (aspnet server should not be rebooted).
- Exception is thrown as
redis server is not available
The AsyncTcpClient changes to a Connected state, but the Available property is still false.
Changing the property before returning solved the issue for me:
this.Available = true;
return new Result { ResultType = ResultType.Simple, Messge = "Connected" };
I think the cause is the parallel Ping from ReadHosts and WriteHosts.
Both will call Connect method, but one that fails may flag the mConnected
field as false, while the second thread has set as true
.
https://github.com/beetlex-io/BeetleX/blob/ce6f9d91394dbed5f28a66b9efbd9a87f9d32e23/src/BeetleX/Clients/Clients.cs#L1019-L1105
thanks