matrix-org / dendrite

Dendrite is a second-generation Matrix homeserver written in Go!
https://matrix-org.github.io/dendrite/
Apache License 2.0
5.67k stars 664 forks source link

`bcrypt_cost: 20` cause time out when creating account. #2035

Closed p3nj closed 2 years ago

p3nj commented 2 years ago

Description

This happens inside a environment spec list below:

Inside dendrite.yaml under user_api section if bcrypt_cost is set to 20, it will cause client service to timed out when using monolith docker setup. Eventually it will return CORS error but it is because bcrypt is taking too long that HTTP request would not willing to wait.

Background information

docker container logs

if you check the dendrite container log it will only shows two lines of log about making request to create account, but no error messages and nothing else.

nginx error logs

nginx error log will only shows that can not connect to upstream and time out the request.

Steps to reproduce

since the configuration file shows max bcrypt_cost is limited to 31, it will be nice if when account creation request is made, http request is willing to wait until bcrypt calculation is finished.

kegsay commented 2 years ago

Increasing the bcrypt cost increases the CPU time used and hence total time taken. The cost you should use will vary based on:

Two cores (assuming that's the 2C in 2C4G) on a DO droplet simply is too slow for bcrypt cost this high. Lower it. For more information on this, see https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#work-factors