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

Add max attempt on URL generation #51

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sj902
Copy link

@sj902 sj902 commented Feb 2, 2024

Adds a limit on the maximum number of retries in case of collisions.

Closes Issue #50

MAIN_SITE_HOST=1px.li
URL_GEN_MAX_RETRIES=1000
Copy link
Owner

Choose a reason for hiding this comment

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

production retries should not be 1000 either, 10 is a better limit
commenting below, why the error message is not good

Copy link
Author

Choose a reason for hiding this comment

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

Changed it to 10

@@ -53,6 +54,10 @@ var (
status: fiber.ErrForbidden.Code,
message: "this shortURL is not allowed to be created",
}
MaxRetriesReachedError = &UrlError{
status: fiber.ErrInternalServerError.Code,
message: "max number of attempts to generate a URL reached. Please try after some time",
Copy link
Owner

Choose a reason for hiding this comment

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

so this is not a good error to give the client, because the client is technically not "retrying" these many times. It is our code's internal recursion causing it.

A 508 StatusLoopDetected error with message "server exhausted attempts to generate a unique shortUrl, please try again" would be better

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Have updated the message.

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