Base solution for your next web application
Open Closed

Multi-Tenant Issues after build agents upgraded to 3.1 #8833


User avatar
0
twopenguinsstudios created

Azure has recently updated all their build agents to Core 3.1. We are using the the Core version 2.2. All of a sudden we are seeing users being kicked out of the system throughout the day and in the logs we see

System.Exception: There is no user: 28

I believe in the multi-tenant structure it should have a tenant appended to that like 28@2 or something. I know core 3.1 changed how multi-tenancy works but am not sure how exactly its implemented in the framework here.

We tried changing the build agent to force using the 2.2 SDK and are waiting to see if this has a result but I wanted to open a ticket to see if anyone else is having this issue or has any ideas.

Thanks in advance.


16 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @twopenguinsstudios,

    Detecting the current tenant haven't been changed for a long time. I assume this is related to something else.

    • Do you use a single database for all tenants ?
    • If so, User with Id=28 belongs to a tenant or host ?
  • User Avatar
    0
    twopenguinsstudios created

    Single database and user Belongs to a tenant. This worked perfect until this week when we deployed on Sunday but there are no code changes related to tenacy and we have not updated the framework.

    The only change is the build agents are now running the latest 3.1 and core is weird in that if you do not specify the SDK version it will try to build with the latest SDK.

    There are breaking changes to the way multi-tenancy works in 3.1 but I havne't been able to dig into the base code to figure out how it uses multi-tenancy in the middlware. https://michael-mckenna.com/multi-tenancy-compatibility-dot-net-core-three

  • User Avatar
    0
    twopenguinsstudios created

    I've forced the azure pipeline to use the 2.2 SDK and rebuilt the same exact code and so far the issue seems resolved, but this isn't ideal long term.

  • User Avatar
    0
    twopenguinsstudios created

    We are confident now that the downgrade of the SDK on the build agent resolved the issue. What is the path forward with this?

  • User Avatar
    0
    twopenguinsstudios created

    We are also running v7.0.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @twopenguinsstudios,

    I think it will be better to upgrade your project to .NET Core 3.1 in the long term.

  • User Avatar
    0
    twopenguinsstudios created

    Thats fair but for right now any idea why in production we are seeing our users get kicked out throughout the day and seeing errors in the logs related where the Get user is called with a user ID and no tenant? The 2.2 version still was a production release that we paid for. We will try to upgrade soon but we need to get people not kicked out.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You are right. I was talking about below statement which is not related to AspNet Zero I think.

    We are confident now that the downgrade of the SDK on the build agent resolved the issue

    Is it possible for you to share the entire error message ?

    Thanks,

  • User Avatar
    0
    twopenguinsstudios created

    So the issue is not resolved. It is still lingering and people are getting kicked out somewhat regularly. We see an error in the logs that looks like this:

    • System.Exception: There is no user: 42

    These are multi-tenant users so that looks very wrong. It should look like this:

    • System.Exception: There is no user: 51@2

    I've inspected the bearer tokens and they have the tenant in them. All the multi-tenant functionality seems to be working well besides this sporadic logout.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    As I understand, it doesn't work with .NET Core 2.2, right ? If that's right, is it possible for you to share your project via email with [email protected] ?

    Thanks,

  • User Avatar
    0
    twopenguinsstudios created

    We cannot reproduce it locally and we have not customized the tenant code. Can't we analyze the version we are using? We are using version 7.0.0

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you can write steps to reproduce this, we can try to reproduce it.

    Thanks,

  • User Avatar
    0
    twopenguinsstudios created

    I found a ticket reporting the same issue, but the links to github are no good. Can you share the fix?

    https://support.aspnetzero.com/QA/Questions/8565

  • User Avatar
    0
    twopenguinsstudios created

    I think I tracked it down. The code creating the claims was dependent on a session tenant ID which does not exist at the time of login. but the user is retrieved from the db, that has that value. There is also another both where becuase this code is assuming a session tenant ID, if you log in as a super admin, then log out, then log in as a normal user you may end up with the wrong tenant id attached to your user identifier!

    var userIdentifier = new UserIdentifier(AbpSession.TenantId, Convert.ToInt64(nameIdClaim.Value));

    var userIdentifier = new UserIdentifier(user.TenantId??AbpSession.TenantId, Convert.ToInt64(nameIdClaim.Value));

  • User Avatar
    0
    musa.demir created

    Hi @twopenguinsstudios

    I think it is fixed here https://github.com/aspnetzero/aspnet-zero-core/commit/434103691c7282d2f243d2291643ae4d0901cf44 and the links are not broken. Your github account probably does not have access to aspnet-zero-core project.

    You can add your github account via https://aspnetzero.com/LicenseManagement page:

  • User Avatar
    0
    twopenguinsstudios created

    Thanks, we are now in and that fix is almost the same as the fix I posted. We'll update the code to match this.