{"action":"created","issue":{"url":"https://api.github.com/repos/framework-one/fw1/issues/329","labels_url":"https://api.github.com/repos/framework-one/fw1/issues/329/labels{/name}","comments_url":"https://api.github.com/repos/framework-one/fw1/issues/329/comments","events_url":"https://api.github.com/repos/framework-one/fw1/issues/329/events","html_url":"https://github.com/framework-one/fw1/issues/329","id":76784335,"number":329,"title":"possible race condition in DI1 when using the init method of beans ","user":{"login":"jcberquist","id":3498220,"avatar_url":"https://avatars.githubusercontent.com/u/3498220?v=3","gravatar_id":"","url":"https://api.github.com/users/jcberquist","html_url":"https://github.com/jcberquist","followers_url":"https://api.github.com/users/jcberquist/followers","following_url":"https://api.github.com/users/jcberquist/following{/other_user}","gists_url":"https://api.github.com/users/jcberquist/gists{/gist_id}","starred_url":"https://api.github.com/users/jcberquist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcberquist/subscriptions","organizations_url":"https://api.github.com/users/jcberquist/orgs","repos_url":"https://api.github.com/users/jcberquist/repos","events_url":"https://api.github.com/users/jcberquist/events{/privacy}","received_events_url":"https://api.github.com/users/jcberquist/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/framework-one/fw1/labels/blocker","name":"blocker","color":"5319e7"},{"url":"https://api.github.com/repos/framework-one/fw1/labels/bug","name":"bug","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/framework-one/fw1/milestones/16","html_url":"https://github.com/framework-one/fw1/milestones/3.1","labels_url":"https://api.github.com/repos/framework-one/fw1/milestones/16/labels","id":1019840,"number":16,"title":"3.1","description":"Incremental improvements to 3.0.","creator":{"login":"seancorfield","id":43875,"avatar_url":"https://avatars.githubusercontent.com/u/43875?v=3","gravatar_id":"","url":"https://api.github.com/users/seancorfield","html_url":"https://github.com/seancorfield","followers_url":"https://api.github.com/users/seancorfield/followers","following_url":"https://api.github.com/users/seancorfield/following{/other_user}","gists_url":"https://api.github.com/users/seancorfield/gists{/gist_id}","starred_url":"https://api.github.com/users/seancorfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seancorfield/subscriptions","organizations_url":"https://api.github.com/users/seancorfield/orgs","repos_url":"https://api.github.com/users/seancorfield/repos","events_url":"https://api.github.com/users/seancorfield/events{/privacy}","received_events_url":"https://api.github.com/users/seancorfield/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":24,"state":"open","created_at":"2015-03-13T05:58:50Z","updated_at":"2015-06-25T03:28:46Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-05-15T16:44:49Z","updated_at":"2015-06-25T04:24:10Z","closed_at":null,"body":"I make use of the feature of DI1 that lets you return something other than the created bean via the init method, where that replaces the original bean in DI1. Occasionally I have encountered the situation where if two threads request such a bean at the same time, and it has not yet been cached (I notice this happening on/immediately after a FW1 reload), it is possible for the first request to create the un-inited bean and then before it calls the init method on it, the second request gets back the un-inited bean (since it is already in the beanCache but has not yet been replaced). \r\n\r\nWhile I have noticed this because I expect the original bean to be replaced with a new bean, it seems to me this could be an issue wherever the init() method is used, even when not returning something other than the original bean."},"comment":{"url":"https://api.github.com/repos/framework-one/fw1/issues/comments/115100933","html_url":"https://github.com/framework-one/fw1/issues/329#issuecomment-115100933","issue_url":"https://api.github.com/repos/framework-one/fw1/issues/329","id":115100933,"user":{"login":"seancorfield","id":43875,"avatar_url":"https://avatars.githubusercontent.com/u/43875?v=3","gravatar_id":"","url":"https://api.github.com/users/seancorfield","html_url":"https://github.com/seancorfield","followers_url":"https://api.github.com/users/seancorfield/followers","following_url":"https://api.github.com/users/seancorfield/following{/other_user}","gists_url":"https://api.github.com/users/seancorfield/gists{/gist_id}","starred_url":"https://api.github.com/users/seancorfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seancorfield/subscriptions","organizations_url":"https://api.github.com/users/seancorfield/orgs","repos_url":"https://api.github.com/users/seancorfield/repos","events_url":"https://api.github.com/users/seancorfield/events{/privacy}","received_events_url":"https://api.github.com/users/seancorfield/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T04:24:10Z","updated_at":"2015-06-25T04:24:10Z","body":"@jcberquist I pushed a commit that shows markers around the block of code that would need to be locked. There's a few issues:\r\n\r\n* Right now, the only code with a lock is the bean discovery which is quick\r\n* The `resolveBeanCreate()` block involves resolving other code so it's a lot of code to lock around.\r\n* That code includes a recursive call which makes it very tricky to lock (since it would have to be isolated to a separate function and an additional lock-or-not-lock argument being passed thru).\r\n\r\nIt's a lot of work for an edge case...\r\n\r\n...so here's a suggestion that might also work for you: since this is all about singletons and initialization, consider putting a call to `.load()` in a load listener. That's the approach we've taken at World Singles: we declare a load listener for all our customizations and the very last line is `di1.load()` -- where `di1` is the argument to the load listener function.\r\n\r\nIf that solves your problem, then I'd be inclined to just close this without action. Our problem was mainly due to lazy initialization of singletons so it may not be sufficient to solve your issue. Please let me know."}}