Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay between @security execution and main API logic only when deployed #1647

Open
2 tasks
vinayak-scrrum opened this issue Jun 26, 2024 · 1 comment
Open
2 tasks

Comments

@vinayak-scrrum
Copy link

vinayak-scrrum commented Jun 26, 2024

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Versions:

  • "@types/node": "^20.10.7",
  • "ts-node": "^9.0.0"
  • "typescript": "^5.3.3"
  • "tsoa": "^3.2.1",

Issue Description:
I am experiencing a 5-6 second delay between the execution of the @security decorator and the main API logic, but only when the application is deployed (on azure app service). This issue does not occur locally.

Steps to Reproduce:

  1. I consoled the time at each step from the authentication middleware to the API response.
  2. I have 3 securities in the @security decorator, so the authentication middleware is called 3 times.
  3. The authentication middleware combined execution takes only 1 second.
  4. There is a gap of 4-5 seconds between the last console log in the authentication middleware and the first console log in the API logic.

API Logic:

@Response<ErrorResponse>("Invalid Token")
@Security({
    "security1": ["scope1", "scope2", "scope3"],
    "security2": [],
    "security3": ["scope1", "scope2"]
})
@Post("/")
public async addDemo(@Request() req: IRequest, @Body() reqBody: IDemoRequest): Promise<SuccessResponseWrapped<DemoDocumentJSON>> {
    try {
        console.log(`STEP 1 ${new Date()}`);
        let demo = await this.addDemoService.create(req, reqBody);
        console.log(`STEP 17 ${new Date()}`);
        return this._successResponse(req, demo, "Demo added successfully", 200);
    } catch (error) {
        throw new MyError(error.code, error.message);
    }
}

Authentication Middleware:

export async function expressAuthentication(request: IRequest, securityName: string, scopes?: string[]): Promise<any> {
    try {
        console.log(`Authentication middleware Start - ${new Date()}`);

        if (securityName === "security1") {
            // security1 logic
        } else if (securityName === "security2") {
            // security2 logic
        } else if (securityName === "security3") {
            // security3 logic
        } else {
            // other logic
        }

        console.log(`Authentication middleware End - ${new Date()}`);
    } catch (error) {
        throw new MyError(error);
    }
}

Request for Help:
Can anyone help me understand why there is such a gap and how I can fix it? Any insights or suggestions would be greatly appreciated.

Thank you!

Copy link

Hello there vinayak-scrrum 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant