A client of mine managed to crash the site when creating a form.
He noticed that when opening a form field to add a dependency, the list of dependent elements was empty. While i was troubleshooting i noticed that the following endpoint timed out: /EPiServer/EPiServer.Forms.UI/Stores/formselement/<formfieldId>?parentLink=<parentId>&query=GetAllDependees
After digging around in optimizely dlls i found the code that was the culpit namely EPiServer.Forms.Core.Internal.Dependency.DependencyService -> BuildDependencyList
This method caused a stack overflow exception because FormField#1 had a dependency to FormField#2 and FormField#2 had a dependency to FormField#1.
There are built in safe guards to prevent this from happening. When you open the tool to select which field you want to create a dependency on, you only see fields that doesn't already have a dependency to the field you are working with. So if you have a form with FormField#1, FormField#2 and FormField#3 and you have created a dependency so that FormField#1 is dependant on FormField#2 then if you try to create a dependency on FormField#2 you should only see FormField#3 in the list of possible dependencies.
This safeguard only works on published versions of the form field though. Meaning if you set the dependency between FormField#1 and FormField#2 and don't actually publish that change and then go to FormField#2 and open the list of dependent fields then you will se FormField#1 there even though it has a dependency to FormField#2. If you then publish FormField#2 and go to FormField#1 and also publish that, then you have created a circular dependency and you will crash the application if you try to open the list of dependency fields
What probably needs to be fixed by optimizely is for them to check on publishing that a circular dependency isn't being publish and also making sure that BuildDependencyList doesn't cause stack overflow exception
To reproduce (if above explaination isn't enough)
Create a form
Create two form fields (lets call them field1 and field2)
Create a dependency so field1 is dependant on field2
Save (dont publish)
Create a dependency so field2 is depenant on field1
Publish
Go back to field1
Publish
Open any of the field and try to add a new dependeny. The application will crash when you open the tooling to pick which field the current field should be dependant on
A client of mine managed to crash the site when creating a form.
He noticed that when opening a form field to add a dependency, the list of dependent elements was empty.
While i was troubleshooting i noticed that the following endpoint timed out: /EPiServer/EPiServer.Forms.UI/Stores/formselement/<formfieldId>?parentLink=<parentId>&query=GetAllDependees
After digging around in optimizely dlls i found the code that was the culpit namely EPiServer.Forms.Core.Internal.Dependency.DependencyService -> BuildDependencyList
This method caused a stack overflow exception because FormField#1 had a dependency to FormField#2 and FormField#2 had a dependency to FormField#1.
There are built in safe guards to prevent this from happening. When you open the tool to select which field you want to create a dependency on, you only see fields that doesn't already have a dependency to the field you are working with.
So if you have a form with FormField#1, FormField#2 and FormField#3 and you have created a dependency so that FormField#1 is dependant on FormField#2 then if you try to create a dependency on FormField#2 you should only see FormField#3 in the list of possible dependencies.
This safeguard only works on published versions of the form field though. Meaning if you set the dependency between FormField#1 and FormField#2 and don't actually publish that change and then go to FormField#2 and open the list of dependent fields then you will se FormField#1 there even though it has a dependency to FormField#2. If you then publish FormField#2 and go to FormField#1 and also publish that, then you have created a circular dependency and you will crash the application if you try to open the list of dependency fields
What probably needs to be fixed by optimizely is for them to check on publishing that a circular dependency isn't being publish and also making sure that BuildDependencyList doesn't cause stack overflow exception
To reproduce (if above explaination isn't enough)
Open any of the field and try to add a new dependeny. The application will crash when you open the tooling to pick which field the current field should be dependant on