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
Servlet.service called before Servlet.init is finished when servlet is lazily initialized #4351
Comments
This discovery might explain what we saw (once) in #4327 |
Looks like we changed the code in commit d48c258#diff-0d419a5cace2d3e164cd481d96f24734 that changed the way we do servlet initialization. When 2 requests come in simultaneously, they are only both checking if the servlet instance is non-null: one will create the instance and then go on to initialize it, meanwhile the second request sees the created-but-not-yet-completely-initialized instance and uses it. Working on a fix. |
So this is a real problem... in which case we should say that the work around is to mark your servlets as initialise on startup. |
Signed-off-by: Jan Bartel <janb@webtide.com>
Raised PR #4354. |
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>
…nit-not-atomic Issue #4351 Lazy servlet init is not atomic
Fix committed in time for 9.4.25. |
Jetty version
9.4.24
Java version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
OS type/version
Windows Server 2016
Description
When a servlet is initialized, there is a small time window during which servlet.init is not yet complete, but servlet.service is already called. I don't know if this is a bug, or if this behavior is desirable. But in earlier versions this never happened. I have tried it with version 9.4.18. There Servlet.service is only called when Servlet.init is completed.
Here is an example code to reproduce the issue. With the first request the servlet is initialized. If this takes some time, then the second request calls Servlet.doGet before Servlet.init is terminated. The output is then:
doGet, uri=/req2
init done
doGet, uri=/req1
Like I said, I don't know if that's a bug. But as a user I would find it very helpful if I could assume that all my resources initialized in Servlet.init are safely ready when Servlet.service is called and I don't have to synchronize them myself.
The text was updated successfully, but these errors were encountered: