gregoriusxu / booksleeve

Automatically exported from code.google.com/p/booksleeve
Other
0 stars 0 forks source link

Subscribe method returns before subscription is setup on redis #24

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This will be tricky to reproduce but here's what I'm doing:

- Build and run redis on windows (https://github.com/MSOpenTech/redis).
- Run redis-server and redis-cli
- In the redis-cli run the MONITOR command so that you can see the redis 
commands

I'm implementing the redis/SignalR message bus 
(https://github.com/SignalR/SignalR.Redis/blob/new-scaleout/SignalR.Redis/RedisM
essageBus.cs) and I'm seeing an issue where the Subscribe method is returning 
without a subscription being fully setup on redis. The method returns void so 
it seems there's no way to wait until that happens.

This block of code:
https://github.com/SignalR/SignalR.Redis/blob/new-scaleout/SignalR.Redis/RedisMe
ssageBus.cs#L32

Is the one giving trouble since the task returns and I'm able to send to the 
connection without the subscription being setup. This causes me to miss 
messages. 

The current hack I have is to do something like this:
while (_channel.SubscriptionCount == 0)
{
    System.Threading.Thread.Sleep(500);
}

It's horrible but it's temporary until I find a solution or workaround.

Original issue reported on code.google.com by davidf...@gmail.com on 17 Sep 2012 at 9:16

GoogleCodeExporter commented 8 years ago
A better workaround would be to issue a "ping" or *any other command* (a "get" 
on "doesnotexist" for example), and wait on *that second command*, but yes, I 
can see how you might want to wait on a Task for this. That will be a breaking 
API change, though - but I'll see what I can do.

Original comment by marc.gravell on 17 Sep 2012 at 11:28

GoogleCodeExporter commented 8 years ago
This is awaitable from 1.3 onwards

Original comment by marc.gravell on 15 Apr 2013 at 6:50