StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

RedisConnectionException at each first Connect(), while redis-py and hiredis work fine

Open tw-bert opened this issue 12 years ago • 103 comments

Hi Marc,

Version 1.0.289.0 (nuget, .net 4.0).

When I leave my workstation alone for five minutes, after calling Connect() I get a RedisConnectionException the first time. Immediately retrying does work with no delay at a 90% success rate. No info is written to the supplied TextWriter.

var oCli = ConnectionMultiplexer.Connect("srv-flux-01:14144", log);

Complete exception message:

An unhandled exception of type 'StackExchange.Redis.RedisConnectionException' occurred in StackExchange.Redis.dll
Additional information: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail

I connect from Win7 Pro X64 to Redis 2.8.9 (x64) on a Debian machine on our LAN (same subnet). No hardware firewalls in between, only Windows firewall. Redis connections from redis-py or RedisDesktopManager(which uses hiredis) never fail, and always connect within milliseconds.

I use a simple Windows Forms project, VS2013 Express, for testing. I use (and need) the .NET Framework 4 Client Profile.

Any ideas?

Kind regards, TW

tw-bert avatar May 09 '14 23:05 tw-bert

If you pass in a writer for the "log", what does it say? On 10 May 2014 00:27, "tw-bert" [email protected] wrote:

Hi Marc,

Version 1.0.289.0 (nuget, .net 4.0).

When I leave my workstation alone for five minutes, after calling Connect() I get a RedisConnectionException the first time. Immediately retrying does work with no delay at a 90% success rate. No info is written to the supplied TextWriter.

var oCli = ConnectionMultiplexer.Connect("srv-flux-01:14144", log);

Complete exception message:

An unhandled exception of type 'StackExchange.Redis.RedisConnectionException' occurred in StackExchange.Redis.dll Additional information: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail

I connect from Win7 Pro X64 to Redis 2.8.9 (x64) on a Debian machine on our LAN (same subnet). No hardware firewalls in between, only Windows firewall. Redis connections from redis-py or RedisDesktopManager(which uses hiredis) never fail, and always connect within milliseconds.

I use a simple Windows Forms project, VS2013 Express, for testing. I use (and need) the .NET Framework 4 Client Profile.

Any ideas?

Kind regards, TW

— Reply to this email directly or view it on GitHubhttps://github.com/StackExchange/StackExchange.Redis/issues/42 .

mgravell avatar May 10 '14 07:05 mgravell

The log stays empty.

tw-bert avatar May 10 '14 09:05 tw-bert

I did some further testing.

When I first create a BookSleeve.RedisConnection, and immediately after that a StackExchange.Redis.ConnectionMultiplexer , the booksleeve connection is valid (without pause), and the stackexchange.redis connection throws an exception.

I also had a situation where I could not connect until I restarted the exe (or started debugging again).

I also tried a "resolvedns=1" option I found in your sourcecode, but this doesn't seem to have any effect (on resolving this issue).

When the exception is not thrown, the log looks like this:

srv-flux-01:14144

1 unique nodes specified
Requesting tie-break from srv-flux-01:14144 > __Booksleeve_TieBreak...
Allowing endpoints 00:00:01 to respond...
srv-flux-01:14144 returned with success
srv-flux-01:14144 had no tiebreaker set
Single master detected: srv-flux-01:14144
srv-flux-01:14144: Standalone v2.8.9, master; 1 databases; keep-alive: 00:01:00; int: ConnectedEstablished; sub: ConnectedEstablished, 1 active
srv-flux-01:14144: int ops=11, qu=0, qs=1, qc=0, wr=0, sync=9, socks=1; sub ops=3, qu=0, qs=0, qc=0, wr=0, subs=1, sync=3, socks=1
Circular op-count snapshot; int: 0+11=11 (1,10 ops/s; spans 10s); sub: 0+3=3 (0,30 ops/s; spans 10s)
Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
Starting heartbeat...

Kind regards, TW

tw-bert avatar May 10 '14 14:05 tw-bert

The log is never empty. It should always say something. Try passing in a StringWriter, then write the ToString afterwards. On 10 May 2014 10:52, "tw-bert" [email protected] wrote:

The log stays empty.

— Reply to this email directly or view it on GitHubhttps://github.com/StackExchange/StackExchange.Redis/issues/42#issuecomment-42737620 .

mgravell avatar May 10 '14 16:05 mgravell

Hi Marc, I used a StreamWriter (which I flushed in the finally). I'll try a StringWriter in a few days (can't access my work environment atm) and get back here.

tw-bert avatar May 10 '14 20:05 tw-bert

Yes, a StringWriter does give back a result:

---------------------------

---------------------------
StackExchange.Redis.RedisConnectionException: It was not possible to connect to
the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail

   at StackExchange.Redis.ConnectionMultiplexer.Connect(String configuration,
TextWriter log) in
c:\TeamCity\buildAgent\work\58bc9a6df18a3782\StackExchange.Redis\StackExchange\Redis\
ConnectionMultiplexer.cs:line 738

   at stackexchange_redis_test_three.Form1.button1_Click(Object sender, EventArgs
e) in
e:\work\eclipse\11.3A\amdir_gui\amdir\amber\msroot\msflux\logic_cs_dotnet\stackexchan
ge_redis_test_three\Form1.cs:line 29

srv-flux-01:14144



1 unique nodes specified

Requesting tie-break from srv-flux-01:14144 > __Booksleeve_TieBreak...

Allowing endpoints 00:00:01 to respond...

srv-flux-01:14144 did not respond

srv-flux-01:14144 failed to nominate (WaitingForActivation)

No masters detected

srv-flux-01:14144: Standalone v2.0.0, master; keep-alive: 00:01:00; int:
Connecting; sub: ConnectedEstablished, 1 active; not in use: DidNotRespond

srv-flux-01:14144: int ops=0, qu=4, qs=0, qc=0, wr=0, socks=1; sub ops=3, qu=0,
qs=0, qc=0, wr=0, subs=1, sync=3, socks=1

Circular op-count snapshot; int: 0 (0,00 ops/s; spans 10s); sub: 0+3=3 (0,30
ops/s; spans 10s)

Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago

Starting heartbeat...


---------------------------
OK   
---------------------------

When it goes wrong, it keeps going wrong within that process (some static condition it seems). Same as before: other redis clients have no problems. When I start a second .NET StackExchange.Redis instance next to the first, the second succeeds, while the first keeps on failing.

I can now reproduce this behaviour by issuing:

ipconfig /release & ipconfig /renew

Sidenote: when I did only the release, I lost my RDP connection, duh. Makes perfect sense lol. By combining the two statements, RDP will be disconnected as well, but at least you can connect again after a few seconds.

If StackExchange.Redis' connect is the first thing I do after renew, it fails with the RedisConnectionException above.

Any idea?

tw-bert avatar May 12 '14 18:05 tw-bert

Hi Marc, can you reproduce this?

I'm thinking about returning to BookSleeve, which is always an option ofcourse (and we've had very good experiences with BookSleeve). I can't get StackExchange.Redis to work reliably.

Kind regards, TW

tw-bert avatar May 14 '14 08:05 tw-bert

I am still investigating

On 14 May 2014 09:22, tw-bert [email protected] wrote:

Hi Marc, can you reproduce this?

I'm thinking about returning to BookSleeve, which is always an option ofcourse (and we've had very good experiences with BookSleeve). I can't get StackExchange.Redis to work reliably.

Kind regards, TW

— Reply to this email directly or view it on GitHubhttps://github.com/StackExchange/StackExchange.Redis/issues/42#issuecomment-43054423 .

Regards,

Marc

mgravell avatar May 14 '14 09:05 mgravell

Great, thanks. And take your time. Give me a nudge if I can help.

tw-bert avatar May 14 '14 09:05 tw-bert

I also had a similar issue. Add I used a RetryPolicy to avoid it.

SiqiLu avatar May 28 '14 03:05 SiqiLu

@SiqiLu How did you configure your retry policy ? I've noticed that with a IIS hosted application, the error keeps coming once its there no matter how hard I try. The only thing to do is restarting the IIS application pool. So I'm surprised that you managed to solve this with just a retry policy.

blemasle avatar May 28 '14 08:05 blemasle

@SiqiLu I second blemasle's question. A workaround like 'restarting the .NET process' does not work for me (because it's somewhere inside a running .NET Gui client).

A self-quote from earlier in this thread:

When it goes wrong, it keeps going wrong within that process (some static condition it seems). Same as before: other redis clients have no problems. When I start a second .NET StackExchange.Redis instance next to the first, the second succeeds, while the first keeps on failing.

I can reproduce the exception by issuing:

ipconfig /release & ipconfig /renew

(before the first command of SE.Redis)

Can you (blemasle and SiqiLu) reproduce this?

tw-bert avatar May 28 '14 08:05 tw-bert

I'm still struggling to reliably repro in a way that allows code fix; haven't given up, but it is just vexing that I'm fighting Socket here..

On 28 May 2014 09:43, tw-bert [email protected] wrote:

@SiqiLu https://github.com/SiqiLu I second blemasle's question. A workaround like 'restarting the .NET process' does not work for me (because it's somewhere inside a running .NET Gui client).

A self-quote from earlier in this thread:

When it goes wrong, it keeps going wrong within that process (some static condition it seems). Same as before: other redis clients have no problems. When I start a second .NET StackExchange.Redis instance next to the first, the second succeeds, while the first keeps on failing.

I can reproduce the exception by issuing:

ipconfig /release & ipconfig /renew

(before the first command of SE.Redis)

Can you (blemasle and SiqiLu) reproduce this?

— Reply to this email directly or view it on GitHubhttps://github.com/StackExchange/StackExchange.Redis/issues/42#issuecomment-44379568 .

Regards,

Marc

mgravell avatar May 28 '14 11:05 mgravell

ipconfig /release & ipconfig /renew

does not give a reliable repro for you?

tw-bert avatar May 28 '14 11:05 tw-bert

I am pushing a new build which hopefully should help with this; basically, it moves some retry logic down into the library. In my tests over a VPN, simply: sometimes the socket connect doesn't ever complete, and the only thing to do is to take off and nuke it from orbit.

On 28 May 2014 12:26, tw-bert [email protected] wrote:

ipconfig /release & ipconfig /renew

does not give a reliable repro for you?

— Reply to this email directly or view it on GitHubhttps://github.com/StackExchange/StackExchange.Redis/issues/42#issuecomment-44394442 .

Regards,

Marc

mgravell avatar May 28 '14 16:05 mgravell

Newest version fixed my issue, thanks!

BillMcCrary avatar May 29 '14 20:05 BillMcCrary

I ran accross a "No connection is available for the operation" exception now. This occurs on the first redis operation that is done at the application startup. A refresh (and so re issue the command) seems to fix the problem thought. Any idea ?

blemasle avatar May 30 '14 12:05 blemasle

I confirm that I face the exact same problem. It has "simply" been relocated elsewhere. Before : crashes while establishing the connection After : crashes on each arbitrary operation requested, eg : "No connection is available to service this operation: ZRANGE my:key".

Retrying the operation keeps crashing, while reloading the pool works most of the time.

blemasle avatar Jun 02 '14 08:06 blemasle

Thanks for the newest version. I will try it after returning to my work. Also I will recheck whether my retry policy working.

SiqiLu avatar Jun 02 '14 08:06 SiqiLu

@blemasle I am in my holiday now without my code.I will retry my solution just after returning.

SiqiLu avatar Jun 02 '14 08:06 SiqiLu