-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Issue #4351 Lazy servlet init is not atomic #4354
Conversation
Signed-off-by: Jan Bartel <janb@webtide.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/InitServletTest.java
Outdated
Show resolved
Hide resolved
Am I right in assuming that this only applies to Servlets that do not have the So in a hypothetical setup where let say a |
@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>
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java
Outdated
Show resolved
Hide resolved
This reverts commit 5bc6593.
Signed-off-by: Jan Bartel <janb@webtide.com>
Code cleanup. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@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. |
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.