{"action":"closed","issue":{"url":"https://api.github.com/repos/unitycontainer/container/issues/22","repository_url":"https://api.github.com/repos/unitycontainer/container","labels_url":"https://api.github.com/repos/unitycontainer/container/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/unitycontainer/container/issues/22/comments","events_url":"https://api.github.com/repos/unitycontainer/container/issues/22/events","html_url":"https://github.com/unitycontainer/container/issues/22","id":264984368,"number":22,"title":"Potential not thread-safe behaviour in SynchronizedLifetimeManager","user":{"login":"ENikS","id":1750155,"avatar_url":"https://avatars2.githubusercontent.com/u/1750155?v=4","gravatar_id":"","url":"https://api.github.com/users/ENikS","html_url":"https://github.com/ENikS","followers_url":"https://api.github.com/users/ENikS/followers","following_url":"https://api.github.com/users/ENikS/following{/other_user}","gists_url":"https://api.github.com/users/ENikS/gists{/gist_id}","starred_url":"https://api.github.com/users/ENikS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ENikS/subscriptions","organizations_url":"https://api.github.com/users/ENikS/orgs","repos_url":"https://api.github.com/users/ENikS/repos","events_url":"https://api.github.com/users/ENikS/events{/privacy}","received_events_url":"https://api.github.com/users/ENikS/received_events","type":"User","site_admin":false},"labels":[{"id":707943591,"url":"https://api.github.com/repos/unitycontainer/container/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/unitycontainer/container/milestones/4","html_url":"https://github.com/unitycontainer/container/milestone/4","labels_url":"https://api.github.com/repos/unitycontainer/container/milestones/4/labels","id":2854569,"number":4,"title":"5.2.1","description":"","creator":{"login":"ENikS","id":1750155,"avatar_url":"https://avatars2.githubusercontent.com/u/1750155?v=4","gravatar_id":"","url":"https://api.github.com/users/ENikS","html_url":"https://github.com/ENikS","followers_url":"https://api.github.com/users/ENikS/followers","following_url":"https://api.github.com/users/ENikS/following{/other_user}","gists_url":"https://api.github.com/users/ENikS/gists{/gist_id}","starred_url":"https://api.github.com/users/ENikS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ENikS/subscriptions","organizations_url":"https://api.github.com/users/ENikS/orgs","repos_url":"https://api.github.com/users/ENikS/repos","events_url":"https://api.github.com/users/ENikS/events{/privacy}","received_events_url":"https://api.github.com/users/ENikS/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":1,"state":"open","created_at":"2017-10-20T15:26:11Z","updated_at":"2017-11-13T21:05:13Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2017-10-12T15:24:22Z","updated_at":"2017-11-13T21:05:13Z","closed_at":"2017-11-13T21:05:13Z","author_association":"OWNER","body":"@pbaravik wrote:\r\n\r\nTo my mind the code of the method SynchronizedLifetimeManager.GetValue() contains potentially unsafe code:\r\n\r\n```\r\npublic override object GetValue()\r\n{    \r\n  Monitor.Enter(this.lockObj);    \r\n  object obj2 = this.SynchronizedGetValue();    \r\n  if (obj2 != null)    \r\n  {\r\n    Monitor.Exit(this.lockObj);    \r\n  }    \r\n  return obj2;\r\n}\r\n```\r\n\r\nThe scenario might be the following:\r\n* the thread captures the lock object \r\n* SynchronizedGetValue() returns null \r\n  * I did not find that Recovery would be called if null resolved and thus sync block remains captured\r\n* the thread leaves Unity code \r\n* the thread is terminated for any reason\r\n* the deadlock situation will take place.\r\n\r\nSample output of WinDbg SOS extensions deadlock analysis (real case):\r\n\r\n0:045> !dlk\r\nExamining SyncBlocks...\r\nScanning for ReaderWriterLock(Slim) instances...\r\nScanning for holders of ReaderWriterLock locks...\r\nScanning for holders of ReaderWriterLockSlim locks...\r\nExamining CriticalSections...\r\nScanning for threads waiting on SyncBlocks...\r\nScanning for threads waiting on ReaderWriterLock locks...\r\nScanning for threads waiting on ReaderWriterLocksSlim locks...\r\nScanning for threads waiting on CriticalSections...\r\n*DEADLOCK DETECTED*\r\nCLR Thread 0x14 is waiting for orphaned SyncBlock 0000000012a3f508 OBJ:000000037f47c750[System.Object]\r\nThe lock was orphaned by CLR thread 0x2ef, which has since terminated.\r\nCLR Thread 0x14 is waiting at Microsoft.Practices.Unity.SynchronizedLifetimeManager.GetValue()(+0xb IL,+0x12 Native)\r\n\r\n1 deadlock detected.\r\n\r\n"}}
{"actor":{"display_login":"ENikS"}}