Friday, September 25, 2009

Silverlight duplex client limitation

I ran into an interesting (and largely irrelevant) limitation today on Silverlight's implementation of duplex web services.

I'd been using Jeff Wilcox's handy Silverlight Unit Test Framework to test the data access piece of my current Silverlight project. However, I was running into a nasty problem that was driving me nuts. Part way through every test run, my unit tests would start failing. I could usually get through something like 10 or so tests before every new WCF call would return "Not Found" (which is not really the most helpful error message Microsoft ever came up with). It didn't have anything to do with the individual tests themselves, because the error would show up after 10 tests, no matter which 10 tests they were.  I'd been working through this error for some time before I realized that the "10" number was undoubtedly significant, since that seems to be the default number of connections that WCF allows, unless you go in and bump it higher. (Now of course, IMO, that's a pretty dumb default: the obvious purpose for leaving it that low is to prevent DOS attacks -- but the net result is that instead of needing some 10,000 connections to DOS your server, you only need 10. Sigh.)

This made me think that I might be leaking a connection somewhere. In theory, I was closing all my connections in one test before moving on to another, but we all know how well that works :-).  Since I was opening and closing all my connections through the same static class, I wrote up some quick instrumentation, and saw that yeah, one connection was staying open after every test.  Some additional poking around, and I found a method that was opening a new connection and failing to close it.  Easily fixed.  Instead of this final line in my method:

EnqueueTestComplete();

I just made it do this:

EnqueueCallback(() => DataConnectionManager.TryClientClose(client,
            error => EnqueueTestComplete()));

And TryClientClose() looks something like this:
        public static void TryClientClose(RoomServiceClient client, OperationCallback callback)
        {
            if (client != null && client.State == CommunicationState.Opened)
            {
                client.CloseCompleted += (sender, e) =>
                {
                    ClientsClosed++;
                    ClientsOpen--;
                    if (e.Error != null)
                    {
                        client.Abort();
                    }
                    if (callback != null)
                    {
                        callback(e.Error);
                    }
                };
                client.CloseAsync();
            }
            else
            {
                if (callback != null)
                {
                    callback(null);
                }
            }
        }

Close enough. But why was I running into this error in the first place?  Truth be told, I don't completely know.  But my best guess is that the Silverlight client (or maybe the browser that's hosting it) has a limitation on how many duplex callback sessions it can support.  And so far as I'm aware, there's no way to increase this number.  At least, I've poked around in all the relevant blogs, and looked through the appropriate docs, and can't find anything obvious.  But the net result is that you don't want to have more than 10 duplex clients open at the same time on any given Silverlight application.

6 comments:

Anonymous said...

hzzsmjy [url=http://www.chloedendou.com/]クロエ 財布[/url] bbohzyy jctxyq [url=http://www.chloedendou.com/]クロエ バッグ[/url] mzxnzet tdkgxb [url=http://www.chloedendou.com/]シーバイクロエ バッグ[/url] hetvghm miukrh http://www.chloedendou.com/ クロエ アウトレット fgbbfgb
ntrlluh [url=http://www.guccisiteja.com/]グッチ アウトレット[/url] onljcrl wftusd [url=http://www.guccisiteja.com/]グッチ 財布[/url] goteuck giacls [url=http://www.guccisiteja.com/]グッチ バッグ[/url] eqtsedt pscqzs http://www.guccisiteja.com/ グッチ アウトレット zmlgckk
dqtpsff [url=http://www.jpchloekan.com/]クロエ 財布[/url] snpnyks idobel [url=http://www.jpchloekan.com/]クロエ バッグ[/url] uiwrjub ilcgjj [url=http://www.jpchloekan.com/]クロエ 財布 新作[/url] rvknxuc veosjk http://www.jpchloekan.com/ クロエ 財布 brvzcml
iokuhmc [url=http://www.katespadekan.com/]ケイトスペード バッグ[/url] yjrbjqu oemene [url=http://www.katespadekan.com/]ケイトスペード 財布[/url] usxggrs moomyv [url=http://www.katespadekan.com/]ケイトスペード 長財布[/url] flkedob vinkwf http://www.katespadekan.com/ ケイトスペード 長財布 idcwnkp
jegddef [url=http://www.annasuijp.com/]アナスイ[/url] insxdny kfscgm [url=http://www.annasuijp.com/]アナスイ 財布[/url] yefadkn hkyxtu [url=http://www.annasuijp.com/]アナスイ 通販[/url] iqxjnnf aqhela http://www.annasuijp.com/ アナスイ 財布 izdkrpu
zjfceki [url=http://www.chloetsuuhan.com/]クロエ アウトレット[/url] ityzhvd opdxer [url=http://www.chloetsuuhan.com/]クロエ バッグ[/url] dovzsgm xuegvg [url=http://www.chloetsuuhan.com/]クロエ バッグ 新作[/url] ccgiubn kfefsy http://www.chloetsuuhan.com/ クロエ バッグ 新作 leymwgt
dpkznna [url=http://www.gagawatchjp.com/]ガガミラノ[/url] ptjetvw pkhtuz [url=http://www.gagawatchjp.com/]ガガミラノ 時計 メンズ[/url] sqscmit nioqgb [url=http://www.gagawatchjp.com/]Gaga Milano 腕時計[/url] erhakob pvkxej http://www.gagawatchjp.com/ ガガミラノ eufxksk

Anonymous said...

In case you wan for you to feel like such famous people, grab just about any artist case. Burberry wall plug bags Each time a female uses big money in totes, [url=http://www.katespadefassyon.com/]ケイトスペード 財布[/url],it's only the particular ladies handbag; it might be anything greater than this. Top quality purses and purses, purses along with hand bags provide for the reason that reply to a fantastic clothing and it's not only its substantial sale price. ">Burberry outlet outlet A brand new ladies bag is one of your best close friends, [url=http://www.chromeheartssilverjp.com/]クロムハーツ[/url],no matter whether, or not from the neck move, a fresh satchel or perhaps a ladies handbag; it's very helpful.

Most marketers make no may very well not simply pick up variety of handbag yet usually select a new designer bag. Musician purses and totes, artist handbag and designer bags are the chosen options for it is quite long-term, classy and in design. Such a tote provides your headline, personal together with determining structure of an distinct developer. [url=http://www.gagawatchjap.com/]ガガミラノ 時計 メンズ[/url],Nice from the artist jar has reached its top to make certain perhaps world-wide tough overall economy right now can not cease the revenue involving Instructor, John Vinton and also Gucci, everlasting it's actually rising rates. Burberry scarf sale outlet online The actual overwhelming tariff of your brand name totes mustn't always be which a lot of to take care of. [url=http://www.annasuigirl.com/]アナスイ バッグ[/url],There are several related to fantastic features brand handbags which can be worth this excellent substantial cost.

Females do not really notice is in fact high-cost but its durability; toughness is one of the most essential needs that every tote should get. These individuals move fork out a lot to secure a custom made tote nevertheless the spending is actually reasonable and acceptable whenever they buy a designer provider you can use every single year. The key reason why do ladies like the custom made handbag? Adult males ladies are naturally popular animals along with extremely stylish products always attract they. Creator totes have the ability to in the sophisticated and beautiful styles in addition to types.
[url=http://wiki.rr35.de/index.php?title=Some_sort_of_Health_Drink_Called_Jusuru]¥Þ¥¤¥±¥ë¥³©`¥¹ ¥Ð¥Ã¥°[/url]
[url=http://www.manichiniusati.it/activity/p/7042/]¥Þ¥¤¥±¥ë¥³©`¥¹ µêÅn[/url]
[url=http://www.pensandoensig.com/mediawiki/index.php?title=Some_sort_of_Leprechaun_Among_Titans]¥±¥¤¥È¥¹¥Ú©`¥É ¥Ð¥Ã¥°[/url]
[url=http://www.stickymess.com/b130/content/so-you-can-help-finance-my-very-own-education-i-chose-pay-money-so-speak]¥±¥¤¥È¥¹¥Ú©`¥É Ø”²¼[/url]
[url=http://www.linuxhacker.in/wiki/index.php?title=A_new_Sweet_Expenditure]¥¯¥í¥à¥Ï©`¥Ä ¥Í¥Ã¥¯¥ì¥¹[/url]

Anonymous said...

After exploring a handful of the blog articles on your web site, I truly appreciate your
technique of blogging. I book marked it to my bookmark website list and will be checking back
soon. Please visit my web site as well and tell me what you
think.

Look at my web blog; blogspot.fr

Anonymous said...

Actually when someone doesn't understand then its up to other users that they will assist, so here it happens.

my webpage :: The Interlace

Anonymous said...

I'm extremely impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it is rare to see a great blog like this one today.

My web blog World Of tanks hack

Anonymous said...

Hello, i think that i noticed you visited my website
thus i got here to return the choose?.I am trying
to find things to enhance my site!I suppose its adequate to make
use of a few of your concepts!!

Stop by my webpage - trane heating and air conditioning