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

Template rendering should be async #5

Open
mkantor opened this issue Sep 2, 2020 · 3 comments
Open

Template rendering should be async #5

mkantor opened this issue Sep 2, 2020 · 3 comments
Milestone

Comments

@mkantor
Copy link
Owner

mkantor commented Sep 2, 2020

Right now handlebars templates are rendered on the thread that's handling the request. I think this could result in denial-of-service if all threads in the actix worker pool are busy rendering templates when a new request comes in. I haven't personally observed this, but it can be confirmed with some load testing (maybe using templates that get content from a slow executable or large static file).

The handlebars library is inherently blocking, but Operator's availability could still be improved by moving rendering to another thread (and preferably deferring it until the Stream is polled).

Unfortunately there are tradeoffs regarding how render errors are surfaced. Currently clients get a nice HTTP 500 if a template explodes, but with this change they'd become stream errors (which are not as obvious in browsers). Executables already work like that (an executable which exits with failure is still 200 OK), so maybe that's okay.

@mkantor mkantor added this to the 1.0 milestone Sep 3, 2020
@mkantor
Copy link
Owner Author

mkantor commented May 8, 2021

I did some exploration on this a while ago, but decided to wait until actix-web v4 and handlebars v4 are out of beta to really dig in. I've forgotten the details by now, but there are some API changes in handlebars especially that should make this easier to implement (I think they were related to sunng87/handlebars-rust#395 and sunng87/handlebars-rust#390).

@mkantor
Copy link
Owner Author

mkantor commented Jul 15, 2021

Should keep an eye on sunng87/handlebars-rust#436, and consider looking into that myself if it's been abandoned. It would be awesome if handlebars-rust had async render APIs, and even better if it supported async helpers too.

@mkantor
Copy link
Owner Author

mkantor commented May 4, 2022

spawn_blocking or something like it may be the way to go here.

In any case, now that actix-web v4 has been released the first step should be migrating to that (which will also bring in a modern version of Tokio).

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