Developer forum

Forum » Development » ActiveStateChanged triggers on recycle

ActiveStateChanged triggers on recycle

Kasper Pedersen
Reply

Hello, 

I have an issue, where my application keeps failing when i am releasing and the app recycles.

I've located the issue in a NotificationSubscriber on Standard.Page.ActiveStateChanged Notification.

We use this to make an api call to our CDN provider and clear the cache of the page that becomes inactive.

I then found that the error on application start is a stack overflow error because we send a api request for each inactive page on the site.

Is there a way to make sure that our NotificationSubscriber is not triggered on application start or recycle for every page in the application?

I am on DW 9.17.4 for reference

Thanks 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Kasper

It comes from a check on the property of active when we load it from the database. Default value of that property is true when we contruct a new page and then we set it to false when loading pages from database if they are set to false there - this cause a notification for each page being loaded from DB. We whould change that behavior as that is not how it is meant to behave.

On your solution and version, you can do a Application.BeforeDynamicwebStart notification subscriber and set a value on a static variable that the solution is starting, and then in your statechanged notification check if that static variable is true. Then in the end, create a notification subscriber for Application.AfterDynamicwebStart that sets that variable to false again....

 
Kasper Pedersen
Reply

Hi Nicolai,

Thank you for the response :)

I will try and implement your work around for the time being :)

 
Kasper Pedersen
Reply

Hi again Nicolai, 

I tried your suggestion but this doesn't work as the ActiveStateChanged doesn't trigger until after the AfterDynamicwebStart notification.

I added some logging:

2024-11-14 14:05:14.7767|INFO|Smartpage/Purging/StartUpFlow|BeforeStartUp: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:05:14.7830|INFO|Smartpage/Purging/StartUpFlow|BeforeStartUp: Setting Models.Variables.SolutionIsStartingUp = True
2024-11-14 14:05:35.8064|INFO|Smartpage/Purging/StartUpFlow|AfterStartUp: Models.Variables.SolutionIsStartingUp = True
2024-11-14 14:05:35.8064|INFO|Smartpage/Purging/StartUpFlow|AfterStartUp: Setting Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:06:42.5333|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:06:42.5833|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:06:42.6308|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:06:42.6748|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False

....

 

Do you have another suggestion or another observer I could use to automatically prevent it from triggering?

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Are you using Application.BeforeStart and Application.AfterStart or Application.BeforeDynamicwebStart and Applicatino.AfterDynamicwebStart?

An alternative to AfterDynamicwebStart is to use Standard.Application.BeforeEndRequest and set Models.Variables.SolutionIsStartingUp to false if it is true

 
Kasper Pedersen
Reply

I am using, Application.BeforeDynamicwebStart and Applicatino.AfterDynamicwebStart.

I wil try out the BeforeEndRequest method :)

 
Kasper Pedersen
Reply

Hello again,

I am sorry to say but this doesn't solve the issue as it still triggers before the active state changed.

2024-11-14 14:49:54.1909|INFO|Smartpage/Purging/StartUpFlow|BeforeStartUp: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:49:54.1909|INFO|Smartpage/Purging/StartUpFlow|BeforeStartUp: Setting Models.Variables.SolutionIsStartingUp = True
2024-11-14 14:50:14.6690|INFO|Smartpage/Purging/StartUpFlow|BeforeEndRequest: Models.Variables.SolutionIsStartingUp = True
2024-11-14 14:50:14.6690|INFO|Smartpage/Purging/StartUpFlow|BeforeEndRequest: Setting Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:50:14.8374|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:50:14.8914|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:50:14.9375|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False
2024-11-14 14:50:14.9846|INFO|Smartpage/Purging/StartUpFlow|ActiveStateChanged: Models.Variables.SolutionIsStartingUp = False

...

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

You probably have different things hitting - or the IIS startup page or something.

Maybe set a startup timestamp on BeforeStartUp and do not execute inside ActiveStateChanged unless startup time is at least 60 seconds ago or similar. Or use the timestamp inside BeforeEndRequest to not set the SolutionIsStartingUp to false before a minut has passed.

 

You must be logged in to post in the forum