Multiple Navigation Nodes Problem and Navigation Deadlock in SharePoint 2010

Symtoms:
Issue happens after  August 2012 CU installed for SharePoint Server 2010.

After publishing a new page the site load times start to increase dramatically or page requests don’t finish loading at all. You will see the infamous “An expected error has occurred“-error or if the callstack is enabled and custom errors are turned off in the web.config (CallStack=”true” / customErrors mode=”Off”) you will see a “Request timed out.” error-message.

System.Data.SqlClient.SqlException: Transaction (Process ID 76) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.HasMoreRows()
at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
at Microsoft.SharePoint.SPSqlClient.ExecuteQueryInternal(Boolean retryfordeadlock)
at Microsoft.SharePoint.SPSqlClient.ExecuteQuery(Boolean retryfordeadlock)

PortalSiteMapProvider was unable to fetch children for node at URL: /<site>, message: An unexpected error occurred while manipulating the navigational structure of this Web., stack trace:
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.UpdateNavigationNode(String bstrUrl, Int32 lNodeId, DateTime dateParented, String bstrName, String bstrNodeUrl, Object& pvarProperties, String& pbstrDateModified)
at Microsoft.SharePoint.Navigation.SPNavigationNode.Update()

Resolution:
 SharePoint April 2013 CU

For more details and for workarounds :
http://blogs.msdn.com/b/joerg_sinemus/archive/2013/02/12/february-2013-sharepoint-2010-hotfix.aspx

Advertisements

which process lock my dll

Sometimes you want to know whats happinging at the background or wonder which app or process using specific dll. Or may be like me when try to copy a dll getting error “DLL is used by another process” . So what now ?

Process Explorer is one of great tool for this.

Download:

http://download.sysinternals.com/Files/ProcessExplorer.zip

SyncRoot , lock(this) and Syncronized Pattern

You have an object and you want to use one of function that object as threadsafe you can use lock(object) statement for syncronization. But it can cause a deadlock if you are using “lock(this) ” . it occurs when derived classes want to try lock before your inner function execute and also it never gonna execute , because of your inner function wating first lock to be removed but it never be done here is the DeadLock!!  .

    public class MyClass
    {
        public void DoSomething()
        {
//DO NOT USE locking like this
            lock (this)
            {
               
            }
        }
    }

Dead Lock Example:

        MyClass cs = new MyClass();
        public void ThreadWorker() //this function is called by another thread
        {
            lock (cs) // DEADLOCK !!!
            {
                cs.DoSomething();
            }
        }

Here is the golden rule :

 If you have an internal data structure that you want to prevent simultaneous access to by multiple threads, you should always make sure the object you’re locking on is not public.

The reasoning behind this is that a public object can be locked by anyone, and thus you can create deadlocks because you’re not in total control of the locking pattern.
This means that locking on this is not an option, since anyone can lock on that object. Likewise, you should not lock on something you expose to the outside world.
Which means that the best solution is to use an internal object, and thus the tip is to just use Object.
Locking data structures is something you really need to have full control over, otherwise you risk setting up a scenario for deadlocking, which can be very problematic to handle.

Example

 public class MyClass
    {
// Use an inner object for locking.
        object _SyncRoot = new object();
        public void DoSomething()
        {
            lock (_SyncRoot)
            {
                int val = DateTime.Now.Second;
                Console.WriteLine("1) Do Someting Called by " + Thread.CurrentThread.Name);
                while (val - 1 != DateTime.Now.Second)
                {
                    //do some thing 
                }
                Console.WriteLine("1) out");
            }
        }
    }

Most of syncronization tasks  be used when working on collections  and Syncronized Pattern and  ICollection.SyncRoot Property is already exists for c# collections you dont need to create your own.
But if you have a custom object you can use  Syncronized Pattern for your classes . There is an example of Thread Safe wrapper code:

    class MyClass
    {
        private class SynchronizedClass : MyClass
        {
            private object syncRoot = new object();
            private MyClass _instance;
            public SynchronizedClass(MyClass cls) { _instance = cls; }
            public override bool IsSynchronized { get { return true; } }
            public override void Funk1() { lock (syncRoot) { _instance.Funk1(); } }
            public override void Funk2() { lock (syncRoot) { _instance.Funk2(); } }
        }
        public virtual bool IsSynchronized { get { return false; } }
        public static MyClass Synchronized(MyClass cls)
        {
            if (!cls.IsSynchronized)
                return new SynchronizedClass(cls);
            return cls;
        }
        public virtual void Funk1() { /* Your code here */ }
        public virtual void Funk2() { /* Your code here */ }
    }
See:
http://msdn.microsoft.com/en-us/library/system.collections.icollection.syncroot.aspx
http://stackoverflow.com/questions/728896/whats-the-use-of-the-syncroot-pattern
Happy Codding !!!