Developer forum

Forum » Development » Price provider not thread safe

Price provider not thread safe

Anders Ebdrup
Anders Ebdrup
Reply

Hi Dynamicweb,

 

We have an integrated solution and can now and then see some exceptions in the Event viewer, and it seems like the priceprovider is not thread safe. Please see the exception here:

Exception information:
    Exception type: InvalidOperationException
    Exception message: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at Dynamicweb.Ecommerce.Prices.DefaultPriceProvider.FindPriceInternal(Product product, Double quantity, Currency currency, String unitId, User user, Boolean isInformative, Double quantityAllVariants)
   at Dynamicweb.Ecommerce.Prices.DefaultPriceProvider.FindPrice(Product product, Double quantity, String variantId, Currency currency, String unitId, User user, Double quantityAllVariants)
   at Dynamicweb.Ecommerce.Prices.PriceManager.FindPriceInternal(PriceProvider provider, Product product, Double quantity, String variantId, Currency currency, String unitId, Boolean isInformative, Double quantityAllVariants)
   at Dynamicweb.Ecommerce.Prices.PriceManager.FindPrice(Product product, Double quantity, String variantId, Currency currency, String unitId, Boolean isInformative, Double quantityAllVariants)
   at Dynamicweb.Ecommerce.Orders.OrderLine.FindPrice(Boolean includeUnitId)
   at Dynamicweb.Ecommerce.Orders.OrderLine.get_UnitPrice()
   at Dynamicweb.Ecommerce.Orders.OrderLine.get_Price()
   at Dynamicweb.Ecommerce.Orders.OrderLineCollection.get_Price()
   at Dynamicweb.Ecommerce.Orders.Order.GetPriceBeforeFees(Boolean negativePriceControl)
   at Dynamicweb.Ecommerce.Orders.Order.get_Price()
   at Dynamicweb.Ecommerce.Orders.OrderRepository.Save(Order order, Int32 extranetUserId)
   at Dynamicweb.Ecommerce.Orders.OrderService.Save(Order order, Boolean saveOldVersion)
   at Dynamicweb.Ecommerce.Frontend.Cart.CartCatch.SaveCart(Order cart)
   at Dynamicweb.Ecommerce.Common.Context.SetCart(Order cart)
   at Dynamicweb.Ecommerce.Orders.OrderService.RemoveNoneActiveProducts(Order order)
   at Dynamicweb.Ecommerce.Frontend.Cart.CartCatch.LoadCart()
   at Dynamicweb.Ecommerce.Common.Context.GetCart()
   at Dynamicweb.Ecommerce.LiveIntegration.NotificationSubscribers.ExtranetLogin.OnNotify(String notification, NotificationArgs args)
   at Dynamicweb.Extensibility.Notifications.NotificationManager.Notify(String notification, NotificationArgs eventArgs)
   at Dynamicweb.Frontend.LogOnHandler.LogOn(String username, String password, Boolean onlyActive, Boolean impersonateUser, Int32 impersonateUserId, Boolean loginIfPasswordEncrypted)
   at Dynamicweb.Frontend.SecurityHandler.ExtranetStart()
   at Dynamicweb.Frontend.LoginHandler.ExtranetStart(Int32 pageId)
   at Dynamicweb.Frontend.PageView.Load()
   at Dynamicweb.Frontend.DynamicwebHttpHandler.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 

I hope you can change this?

 

Best regards, Anders

 


Replies

 
Nicolai Pedersen
Reply

Hm... From what I can tell, that collection is residing on the httpcontext.current.items only... Do you have anything that manipulates Product.Prices in custom code? Or any idea in what situations you see this?

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

A possible issue could be in this function: LoadPricesOnProducts(products As ProductCollection), where product prices are set from cache and overwrites current prices if used by reference?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Will investigate...

 
Nicolai Pedersen
Reply

Hi Anders

We would still like to know if you access product.prices?

We have an update ready now where that property is readonly (among other changes).

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

We do not access prices by the api, so the change sounds great.

Is it in the 9.4-branch?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Not yet.

Still in progress.

PriceCollection will be changed to a readonly collection, Product.Prices will be changed to a readonly property (of a readonly collection)

The internals of LoadPricesOnProducts are refactored.

Needs some testing and rewriting of unit tests before we can discuss a release.

BR Nicolai

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Anders

The  runtime exception in the EventViewer, has been fixed in versions 9.5.4 and 9.4.20

Both version released and ready for download here:

http://doc.dynamicweb.com/releases-and-downloads/releases

Let me know if you need any more help regarding this

Kind Regards
Dynamicweb Support
Kristian Kirkholt

Votes for this answer: 1

 

You must be logged in to post in the forum