IISingletonDependency services instantiated multiple times

Topics: Core, General, Troubleshooting
Jul 2, 2013 at 6:20 AM
We're having big issues on our website.

We have a service that launches multiple backgrounds threads whenever the managing IISingletonDependency based service is instantiated.

Problem is that for some reason, it seems to be created multiple times 'after a while'.

By 'after a while' mean that, for example now, it ran just fine for multiple hours yesterday, but when I came back at work today I noticed a spike of threads again. Basing on the thread' names (we added ids) I can see that this singleton service got created 5 times by now.

And it isn't limited to 5 times, before we saw even 10 times.

Any ideas why a singleton dependency would do this? FYI: It really looks like sif orchard tried to restart internally for 4 times.

Any help would greatly be appreciated as our website is constantly going down because of this issue (resources getting starved)

FYI: We're on 1.6
Jul 2, 2013 at 8:44 AM
I think we found it after a day of debugging:

Looks like, for example, the indexer runs in a complete separate work context, including separate instances of 'ISingletonDependency' services.

Would be nice if there was a remark about this somewhere, that even singleton services 'can' be run more than once!
Jul 2, 2013 at 2:17 PM
ISingletonDependency is instantiated once per shell. So each shell gets it's own instance. If shell is restarted for any reason, you'll get a new instance.

You're saying that Orchard tried restarting multiple times - why? That's the source of the issue. Config change, file change, appool recycle, unhandled exception etc. Please attach the debugger or look at /App_Data/Logs.
Jul 2, 2013 at 2:21 PM
Oh it does create them multiple times. Whenever the indexer 'task' kicks in it looks like it create a full new context 'container' (so all singleton dependencies are instantiated again)

This is how we reproduced it:
  • Implement IResourceManifestProvider
  • Let that constrictor reference your singleton service
  • In that singleton service log somehow @ the constructor (we used a 'trick' to do this, could log to debug or something to test)
  • Create a new content item that is indexed and wait for the indexer kicks in
  • When it kicks in, it'll create a new instance of your IResourceManifestProvider implementation and of your singleton service
You make it sound like this wasn't intended?
Jul 8, 2013 at 1:23 PM
Jul 8, 2013 at 5:06 PM
If you mean singletons are instantiated multiple times, please file a bug (maybe you already did :/). This should not be.
May 4, 2015 at 12:48 AM
@AimOrchard Is this issue still standing? Singleton dependencies should get instantiated once per shell. If for some reason this is not happening, please file a bug @ GitHub.