Multiple guest roles gets created

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 лет назад
In nop 3.4, trying to access a static resource file for the first time can create a duplicate guest role.

Steps to reproduce:

1. Open a browser and navigate to any static file that is not on the server. e.g. localhost/some-static-file.png. Cookies needs to be cleared or use private/incognito mode so InsertGuestCustomer gets called. If the website returns a 404, close the browser or reset the cookies again and repeat this step until it returns a 302 to the login page.
2. Go to admin, check customer roles. A duplicate guest role will be created.

If you set a breakpoint at CustomerService.GetCustomerRoleBySystemName, you will notice that the _cacheManager instance randomly switches between the PerRequest and Memory cache manager. The problem is if the MemoryCacheManager is used, then it 'might' return a proxied entity instance from another DbContext that is already disconnected. When InsertGuestCustomer is called, it assigns this 'detached' entity to the newly created guest customer and when _customerRepository.Insert(customer) is called, EF creates another instance of the guest role.

The repo steps above will not work with the demo website. It should work for a new install however.

I could be wrong about the whole detach/attach thing but you guys can figure it out. Too tired to find out what the entity's state is before committing to the db. Thanks
9 лет назад
opiants wrote:
Steps to reproduce...

I cannot reproduce it. I presume you customized the solution some wrong way because it works just fine out of the box.

opiants wrote:
If you set a breakpoint at CustomerService.GetCustomerRoleBySystemName, you will notice that the _cacheManager instance randomly switches between the PerRequest and Memory cache manager

I cannot notice it. It's just not possible. CustomerService uses PerRequestCacheManager (not MemoryCacheManager).

Furthermore, nopCommerce 3.40 even does not handle static files because it has "runAllManagedModulesForAllRequests" set to "false" in web.config file
9 лет назад
a.m. wrote:
Steps to reproduce...
I cannot reproduce it. I presume you customized the solution some wrong way because it works just fine out of the box.


The core isn't customized in anyway. I had my own plugins installed but that's it.

a.m. wrote:

If you set a breakpoint at CustomerService.GetCustomerRoleBySystemName, you will notice that the _cacheManager instance randomly switches between the PerRequest and Memory cache manager
I cannot notice it. It's just not possible. CustomerService uses PerRequestCacheManager (not MemoryCacheManager).


That's what I thought. Although a named parameter isn't hardcoded, I assumed it would always use memcache but this wasn't always true in my case. Maybe it's the way autofac tries to resolve parameters? I don't really know but it does happen not only on the dev machine.

a.m. wrote:

Furthermore, nopCommerce 3.40 even does not handle static files because it has "runAllManagedModulesForAllRequests" set to "false" in web.config file


We have this set to true for some reason. Maybe this is one of the problem but shouldn't it work with this on anyway? Can you test with this on and see what happens?

Also, can you try use curl to guarantee that you're not passing an old cookie.

P.S.  This only started happening after upgrading to 3.4. The site was running 3.1 before and never had this problem.
9 лет назад
opiants wrote:
We have this set to true for some reason. Maybe this is one of the problem but shouldn't it work with this on anyway? Can you test with this on and see what happens?

It works fine even with this setting set to "true". It was set to "true" since first versions. It was set to "false" to improve performance since 3.40.

Maybe, thie issue is in some other place which was customized, maybe plugins, maybe something else. It's not possible to find a real reason without looking at source code. But I can surely say it works fine out of the box.
9 лет назад
I want to report the same issue. An upgrade from 3.1 to 3.4 - I have had about 40 "Guests" roles created since the upgrade went live on the 18th August. Nowhere in the source can I find where a "Guests" role is created, so I assume this is something to do with the internals/entity framework weirdness. I have not been able to create a scenario where a duplicate Guests role is created, but I have a table of them...

I am going to clean them manually from the database and reassign the mapping Id's

also, with regard to the "runAllManagedModulesForAllRequests", we found that we can't deploy the site on our live server without this set to "true" - works fine in development as "false", but I'm not sure if it's something to do with how the server is set up - we were going to look at that at a later date.
9 лет назад
marc wrote:
I want to report the same issue. An upgrade from 3.1 to 3.4 - I have had about 40 "Guests" roles created since the upgrade went live on the 18th August. Nowhere in the source can I find where a "Guests" role is created, so I assume this is something to do with the internals/entity framework weirdness. I have not been able to create a scenario where a duplicate Guests role is created, but I have a table of them...

I am going to clean them manually from the database and reassign the mapping Id's

Try restoring your database to version 3.10, then stop your site in IIS (before running SQL scripts !!!) , run SQL upgrade scripts, upload 3.40 files, now start the site (3.40).

Let me know if it helps
9 лет назад
Thanks for your reply but even if I do that to test I won't be able to use the database, or test if the problem is gone as I can't recreate it - it's also a very busy site - about 1000 orders a month - a lot of data etc. would get lost, the data would be "out of sync". Also, I am a bit confused with the instructions as that was done to the data already when the upgrade was done???. I'd also have to wait to see if a "Guests" role was created, so I couldn't report success or failure easily... sorry.

I will have to come back to this issue as I'm not really in a position to test extensively... the site is actually running great and the client is happy - also, this isn't causing any actual issues with the site, but my client got "worried". The site has had 2795 customer accounts created since 18th August and only 43 of these got the extra "Guests" role, so It's not causing a big problem for us...
9 лет назад
I've had this happen too from time to time, currently on an extremely customised v3.3. I've been meaning to clean out the customers table afresh to start again to see if the problem reoccurs but keep forgetting...too many tasks to work on!

I'll report back of any further updates - I have been switching between runAllManagedRequests but have currently set it to false.
9 лет назад
Same issues happened. At first yes, it is cause by the custom plugins. But after removed all the plugins. The system still creating empty guest roles. At certain period, It will create a lot guests just in few seconds. The largest amount that I have is over 1000 guest has been created.

I also trying to analyze and look into it deeply, but no luck totally can't find out the problem

http://i59.tinypic.com/2vmgi6r.jpg
9 лет назад
Following up with this issue:

we have disabled the Checkout as Guest feature - we have found that in some cases (8 orders out of 400) this issue also causes a mix up after payment. The order didn't get confirmed paid in nop so an email from the payment providers was received by the store manager, but not from nop, then the order had to be traced manually via the email address recieved from the payment provider and the order items are always in their "ShoppingCartItems"

disabling checkout as guest has stopped the order problem - I cleaned up all the extra guest roles and remapped the customers, but there are a number (about 20) of guest roles that have been created since.

obviously with the payment confirmation problem this issue became a problem for us - it's mangable now, but the guests role keep getting created and we are not sure why.

@a.m "I cannot reproduce it. I presume you customized the solution some wrong way because it works just fine out of the box."

Is there anyway of hinting as to what may be doing this - I have a plugin that has an ActionFilterAttribute and FilterProvider, which I believe are as MVC standard so I don't understand how I can resolve this problem - If it is something to do with the plugin then obviously I will change it, but I can't understand what is wrong yet.

In the ActionFilterAttribute I have a category that is hidden from the search unless a user has the "WebShop" role. This "WebShop" role is added on the fly to any user who hits a category that as "WebShop" as it's parent category directly so that all the webshop products become available in their search "session"


            if (actionName.Contains("Category") && filterContext.HttpContext.Request.HttpMethod == "GET")
            {
                try
                {
                    int _categoryId = (int)filterContext.ActionParameters["categoryId"];

                    var username = filterContext.HttpContext.User.Identity.Name;

                    var _categoryRepository = EngineContext.Current.Resolve<IRepository<Category>>();

                    var webshops = _categoryRepository.Table.SingleOrDefault(x => x.Name == "Webshops");

                    if (webshops != null)
                    {
                        var _category = _categoryRepository.Table.SingleOrDefault(x => x.Id == _categoryId);

                        if (_category.ParentCategoryId == webshops.Id)
                        {
                            var _customerService = EngineContext.Current.Resolve<ICustomerService>();

                            var _workContext = EngineContext.Current.Resolve<IWorkContext>();

                            var guestRole = _customerService.GetCustomerRoleBySystemName("WebshopUser");

                            var _customer = _workContext.CurrentCustomer;

                            _customer.CustomerRoles.Add(guestRole);
                        }
                    }
                }
                catch
                {
                    //currentCategoryId ???? 0 ????
                }

            }



In my Filter Provider I'm intercepting Form POSTS - I have a data entity called "ListModule" that has a tab added to the product/edit - when the product is saved the action filter runs a routine on the received form data and saves the record to the database.


using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Mvc;
using System.Data.Entity;
using Nop.Data;
using Nop.Core.Domain.Seo;
using System.Linq;
using Nop.Core.Infrastructure;

namespace Nop.Plugin.Misc.ContentModules.FilterProvider
{
    class POSTProvider : IFilterProvider
    {
        private readonly IDbContext _dbContext;
        private readonly IActionFilter _actionFilter;
        private readonly IListModuleService _listmoduleService;

        public POSTProvider(IDbContext dbContext, IActionFilter actionFilter, IListModuleService listmoduleService)
        {
            this._dbContext = dbContext;
            this._actionFilter = actionFilter;
        }

        public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {

            //List Module Product Data for Edit Product
            if (actionDescriptor.ControllerDescriptor.ControllerType == typeof(Nop.Admin.Controllers.ProductController) && actionDescriptor.ActionName.Equals("Edit") && controllerContext.HttpContext.Request.HttpMethod == "POST")
            {

                NameValueCollection form = controllerContext.HttpContext.Request.Unvalidated.Form;

                var _listmoduleService = EngineContext.Current.Resolve<IListModuleService>();

                if (form["ListModuleId"] != null)
                {
                    _listmoduleService.UpdateRecord(null, form);
                }
                
            }

            return new Filter[]
            {
                new Filter(_actionFilter, FilterScope.Action, null)
            };
        }
    }
}


the _listmoduleService.UpdateRecord parses the form data to update the record.

This system has worked since 3.1 - can anyone assist with this problem?

Thanks.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.