Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
crchauffe #1
User title: Software Engineer
Member since Mar 2013 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: IndexOutOfRangeException when calling PubSubManager.PublishItem
Hi Alex,

I occasionally get an IndexOutOfRangeException when calling PubSubManager.PublishItem.  This is the exception details:

System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Matrix.IqFilter.SendIq(Iq iq, EventHandler`1 callback, Object state) at Matrix.Xmpp.Base.Manager.#=qIYGYZLW11CB_H2Uvv0MfZg==(Iq #=qWim2XN7q1HphdkIutQB2rA==, EventHandler`1 #=qAQUf6GGf1TCCt6_v55eJAw==, Object #=qjzBkTlZe5rcVIe4PNmOGog==) at Matrix.Xmpp.Client.PubSubManager.PublishItem(Jid to, String node, Item item, EventHandler`1 cb, Object state) at Matrix.Xmpp.Client.PubSubManager.PublishItem(Jid to, String node, Item item, EventHandler`1 cb)

Any ideas on what might be causing this?  I believe the XMPPClient.StreamActive doesn't change from true -> false when this happens.  Otherwise, I'd call XMPPClient.Open and reconnect.

I thought this might also be a threading issue -- I call PubSubManager.PublishItem from multiple threads.  However all of my code calls this snippet instead of calling PubSubManager.PublishItem directly:

if (pubsubManager != null)
{
    bool locked = false;
    Monitor.TryEnter(this, 2000, ref locked);
    if (locked)
    {
        pubsubManager.PublishItem("pubsub." + Server, topic, item, PublishResult);

        Monitor.Exit(this);
    }
    else
    {
    }
}

Any thoughts?

Thanks!

-Chad
Avatar
Alex #2
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
this might be a threading problem. All dictionary access is locked, except of the Add method.

Quote by MSDN:
A Dictionary<TKey, TValue> can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. In the rare case where an enumeration contends with write accesses, the collection must be locked during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.
For a thread-safe alternative, see ConcurrentDictionary<TKey, TValue>.
Public static (Shared in Visual Basic) members of this type are thread safe.

which MatriX version are you using? I create a new build then which locks the Add as well.

Alex
Avatar
crchauffe #3
User title: Software Engineer
Member since Mar 2013 · 4 posts
Group memberships: Members
Show profile · Link to this post
which MatriX version are you using? I create a new build then which locks the Add as well.

It looks like I'm using version 1.4.5.2.  I found it by:  right-click the Matrix.dll -> Properties -> Details tab.

I haven't updated in a while.  Has this issue been fixed since 1.4.5.2?  Or will you be addressing it in the next release?

Thanks!
Avatar
Alex #4
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I mean the Platform, .NET, Windows Phone, WinRT etc...
Avatar
crchauffe #5
User title: Software Engineer
Member since Mar 2013 · 4 posts
Group memberships: Members
Show profile · Link to this post
I mean the Platform, .NET, Windows Phone, WinRT etc...

It's the .NET version.

I'm running Openfire v3.7.1 as my XMPP server.
Avatar
Alex #6
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
new build 1.5.3.1 is attached. Please let me know if this fixes your problem.
The author has attached one file to this post:
Release.zip 425 kBytes
You have no permission to open this file.
Avatar
crchauffe #7
User title: Software Engineer
Member since Mar 2013 · 4 posts
Group memberships: Members
Show profile · Link to this post
Thanks!  I'll report my findings in this thread.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS