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

Asynchronous Handling Issue in API Key Hashing Middleware #3338

Merged
merged 4 commits into from
Feb 21, 2025

Conversation

Jatin24062005
Copy link
Contributor

@Jatin24062005 Jatin24062005 commented Feb 8, 2025

Previously, next() was being called after hashing each API key, which caused multiple calls and issues. The new solution uses a pendingTasks counter to wait until all async operations are completed. This fix prevents Mongoose errors and premature next() calls, ensuring proper API key hashing.
The Code i have been manipulated works on the simple principle of critical section problem simmilar to peterson's solution.
These will fix the issue easily .

Fixes #issue-[3016](url)

Changes:

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123

Jatin24062005 and others added 2 commits February 9, 2025 00:03
Previously, next() was being called after hashing each API key, which caused multiple calls and issues.
The new solution uses a pendingTasks counter to wait until all async operations are completed.
This fix prevents Mongoose errors and premature next() calls, ensuring proper API key hashing.
const user = this;
if (!user.isModified('apiKeys')) {
next();
return;
return next();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is a lot neater!

Copy link
Collaborator

@raclim raclim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overall this looks good so far and is actually pretty close to being good to go!

I think one more thing that needs to happen before we merge it is to address the linting errors. So far it seems to pass the other tests, so I think this should be done once that's addressed. I strongly recommend running 'npm run lint' and 'npm run test' on your pull requests before submitting them just to ensure that they're good to go!

now these may work on npm run lint and able to get merge
@Jatin24062005
Copy link
Contributor Author

@raclim i fixed the linting test. now you may merge these from my end.

Copy link
Collaborator

@raclim raclim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the correct one that I meant to approve and merge in 😂 I think there could be some potential further tweaks here in terms of refactoring, but I feel like that could probably be addressed in subsequent PRs and is good for now! Thanks so much again for your work on this!

@raclim raclim merged commit 0b3851c into processing:develop Feb 21, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants