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

Potential fastcgi request ID collision #1

Open
unix1 opened this issue Nov 16, 2017 · 2 comments
Open

Potential fastcgi request ID collision #1

unix1 opened this issue Nov 16, 2017 · 2 comments

Comments

@unix1
Copy link

unix1 commented Nov 16, 2017

On line 45 of cowboy_fastcgi_handler.erl the line says

RequestId = MicroSecs rem 65535,

where RequestId is subsequently used for uniquely identifying a FastCGI request. However, if I'm reading this right, there's 1 in 65536 chance that current request might have the same ID as the previous one. The likelihood of having a duplicate ID goes up as the number of concurrent requests to the application go up.

Simple but not entirely foolproof solution - just increment the previous ID, then wrap around when you reach 2^16.

@marcelog
Copy link
Owner

You might have a point and we could use ets:update_counter for such a thing, but a few points can be made:

  • The requests have to start at exactly the same microsecond for this to be an issue (which is unlikely, at first). But also, I doubt that under those circumstances this is your main problem, because that would mean that there are way too many requests to deal with in a given second, and can easily exceed the capacity of 65535 requests per worker (it doesn't matter how you'd like to count them because that's the limit per worker, 65535).

  • This is only a sample application, with the sole purpose of illustrating how one could use erl_fastcgi, and not a real world application suitable for production :)

@unix1
Copy link
Author

unix1 commented Nov 17, 2017

The requests have to start at exactly the same microsecond for this to be an issue.

Not necessarily. Just that rem 65535 has to be the same.

that would mean that there are way too many requests to deal with in a given second

The requests don't have to start within the same second (even though they could) for their rem 65535ed IDs to collide.

not a real world application suitable for production

OK. Feel free to do as you see fit with this report. I just noticed and thought I'd point out.

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

2 participants