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

Issue #4351 Lazy servlet init is not atomic #4354

Merged
merged 6 commits into from Nov 28, 2019

Conversation

janbartel
Copy link
Contributor

Issue #4351

The code changes in commit d48c258#diff-0d419a5cace2d3e164cd481d96f24734 made the lazy initialization of a servlet non-atomic. Specifically, the bug report shows the situation where request1 comes into the servlet, creates the instance and then calls servlet.init(); meanwhile request2 comes into the servlet and checks if the servlet is non-null, then proceeds to use it. The code around the creation/testing of the servlet instance and the call to servlet.init() needs to be atomic so that request2 cannot use the instance until request1 has finished the call to servlet.init().

The test case I wrote is based on the repro provided by the OP. I fear that as it is reliant on some sleeps to provoke the correct timing to cause the situation, it is likely to be flakey. Any suggestions for a better test are welcome.

Signed-off-by: Jan Bartel <janb@webtide.com>
@janbartel janbartel added this to In progress in Jetty 9.4.25 via automation Nov 25, 2019
Jetty 9.4.25 automation moved this from In progress to Reviewer approved Nov 25, 2019
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sbordet sbordet left a comment

Choose a reason for hiding this comment

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

Since we are modifying ServletHolder, there is an evident search/replace mistake at line 629.
It must be restored to org.apache.catalina.jsp_classpath.

The fix looks good.

The test needs a overhaul because it's way too complicated - it really only need to test the value of the counter, but there are asserts in 3 classes and it's difficult to follow what it does (and lasts to much time).

Jetty 9.4.25 automation moved this from Reviewer approved to Review in progress Nov 25, 2019
@joakime
Copy link
Contributor

joakime commented Nov 25, 2019

Am I right in assuming that this only applies to Servlets that do not have the init-order or load-on-startup configurations set?

So in a hypothetical setup where let say a Filter.init() adds a ServletContext attribute, and a Servlet that needs that attribute, would this PR solve for that as well? (or is this scenario not impacted?)
Taking into account the example reproduction case laid out in #4351

@janbartel
Copy link
Contributor Author

@joakime I don't believe that such a scenario is involved in this fix at all. Filters are never lazily initialized, they are always initialized when their context starts up. This concerns purely the lazy initialization of servlets.

Signed-off-by: Jan Bartel <janb@webtide.com>
Signed-off-by: Jan Bartel <janb@webtide.com>
Signed-off-by: Jan Bartel <janb@webtide.com>
Code cleanup.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@sbordet
Copy link
Contributor

sbordet commented Nov 28, 2019

@janbartel I could not stand empty new lines and indents at 2 spaces rather than 4, so I went on and cleaned up the test code.

Jetty 9.4.25 automation moved this from Review in progress to Reviewer approved Nov 28, 2019
@sbordet sbordet merged commit d7cf372 into jetty-9.4.x Nov 28, 2019
Jetty 9.4.25 automation moved this from Reviewer approved to Done Nov 28, 2019
@sbordet sbordet deleted the jetty-9.4.x-4351-lazy-servlet-init-not-atomic branch November 28, 2019 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Jetty 9.4.25
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants