Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-85

Servlet is initialized twice

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.0.0.Beta2
    • 1.0.0.Beta1
    • Servlet
    • None

      A single servlet defined in web.xml is instantiated and initialized twice, once during Wildfly startup and then again when trying to access the servlet.

      The first time a servlet instance is created is during UndertowDeploymentService.startContext()

      When calling the servlet for the first time, ServletPathMatches.setupServletChains() is called as the previously cached data has been invalidated. During this method it calls Servlets.addServlet() to "re add" each servlet that is part of the deployment.

      Servlets.addServlet() doesn't check whether there is an existing ServletHandler defined for the provided ServletInfo, resulting in a new ManagedServlet and ServletHandler instance being created which then overwrites the previous instance held within the managedServletMap.

      There is initialization performed on GateIn servlets during Wildfly startup, by our own extension, that is then lost when the second instance is created. This results in GateIn being in an inconsistent state as it believes it has already been initialized, though the new servlet instance hasn't.

      Easiest solution seems to be to make Servlets.addServlet() aware of what is already present and not overwrite it, but not sure if there are valid reasons for that overwriting.

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              kfinniga@redhat.com Ken Finnigan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: