bleedingwolf / Ratpack

A micro web framework for Groovy
Other
210 stars 4 forks source link

request delegates not thread safe #26

Closed jimmydivvy closed 11 years ago

jimmydivvy commented 11 years ago

The values 'params' and 'urlparams' etc from the request delegate are not thread safe. If a second request comes into a request handler while the previous one is still processing, the value of 'params' and 'urlparams' are replaced in the namespace of the original request.

My fix is to clone the request handler closure before setting the delegate, thus creating a localized namespace.

This will impart a small performance hit

To replicate the issue:

get ('/testing/:value' ){

Thread.sleep(1000)

return "Value: ${urlparams.value}\n\n";

}

Then run

curl "http://localhost:5000/testing/ONE" & curl "http://localhost:5000/testing/TWO"

Both requests will return the same value (either ONE or TWO, depending on the order the requests execute)

justinvoss commented 11 years ago

This repo is no longer the official Ratpack repo, you'll probably want to visit https://github.com/tlberglund/Ratpack and submit your pull request there. Thanks!

jimmydivvy commented 11 years ago

Submitted there originally. They aren't affected by the bug, however don't consider their branch stable for real use yet.

As this branch appears to still be the basis for most of the ratpack-template projects around (And thus the version most people will currently be using), I figured it worthwhile to share the patch I've used myself to fix the issue on a project I'm working on.

raymyers commented 11 years ago

Thanks, James!