Tiles
  1. Tiles
  2. TILES-204

UrlDefinitionFactory crashes during getDefinitions on multiple requests

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.4
    • Fix Version/s: 2.0.5
    • Component/s: tiles-core
    • Labels:
      None
    • Environment:

      tomcat 5.5

    • Flags:
      Patch

      Description

      consider the following: tiles is initialized using the org.apache.tiles.definition.UrlDefinitionsFactory default definitions factory.

      now, when a request receives and the tiles container is instructed to render a specific tiles definition, the following happens (the interessing parts):

      1. invoke 'Definition getDefinition(String name, TilesRequestContext tilesContext)' of UrlDefinitionFactory.
      2. from there invoke 'Definitions getDefinitions()' of UrlDefinitionFactory.
      3. if the instance attribute 'definitions' is null, from there invoke 'Definitions readDefinitions()' of UrlDefinitionFactory.

      within the third call the configuration is actually parsed and the beans/instances/what ever defined within the configuration file(s) are getting created.
      unfortunatelly the UrlDefinitionFactory does not synchronize the call to the 'Definitions readDefinitions()' method. the result is, if there are multiple request reaching the servlet container at once and there has no other request been received so long, we get into classical multithreading problematics where each thread is bothering the others and the process of creating the definitions list crashs.

      1. UrlDefinitionsFactory.diff
        0.5 kB
        Dirk Alexander Schaefer

        Activity

        Dirk Alexander Schaefer created issue -
        Dirk Alexander Schaefer made changes -
        Field Original Value New Value
        Description hello all,

        consider the following: tiles is initialized using the org.apache.tiles.definition.UrlDefinitionsFactory default definitions factory.

        now, when a request receives and the tiles container is instructed to render a specific tiles definition, the following happens (the interessing parts):

            1. invoke 'Definition getDefinition(String name, TilesRequestContext tilesContext)' of UrlDefinitionFactory.
            2. from there invoke 'Definitions getDefinitions()' of UrlDefinitionFactory.
            3. if the instance attribute 'definitions' is null, from there invoke 'Definitions readDefinitions()' of UrlDefinitionFactory.

        within the third call the configuration is actually parsed and the beans/instances/what ever defined within the configuration file(s) are getting created.
        unfortunatelly the UrlDefinitionFactory does not synchronize the call to the 'Definitions readDefinitions()' method. the result is, if there are multiple request reaching the servlet container at once and there has no other request been received so long, we get into classical multithreading problematics where each thread is bothering the others and the process of creating the definitions list crashs.

        can anyone confirm this?

        greez,

        dialsc
        hello all,

        consider the following: tiles is initialized using the org.apache.tiles.definition.UrlDefinitionsFactory default definitions factory.

        now, when a request receives and the tiles container is instructed to render a specific tiles definition, the following happens (the interessing parts):

            1. invoke 'Definition getDefinition(String name, TilesRequestContext tilesContext)' of UrlDefinitionFactory.
            2. from there invoke 'Definitions getDefinitions()' of UrlDefinitionFactory.
            3. if the instance attribute 'definitions' is null, from there invoke 'Definitions readDefinitions()' of UrlDefinitionFactory.

        within the third call the configuration is actually parsed and the beans/instances/what ever defined within the configuration file(s) are getting created.
        unfortunatelly the UrlDefinitionFactory does not synchronize the call to the 'Definitions readDefinitions()' method. the result is, if there are multiple request reaching the servlet container at once and there has no other request been received so long, we get into classical multithreading problematics where each thread is bothering the others and the process of creating the definitions list crashs.

        greez,

        dialsc
        Antonio Petrelli made changes -
        Summary UrlDefinitionFactory crashs during getDefinitions on multiple requests UrlDefinitionFactory crashes during getDefinitions on multiple requests
        Description hello all,

        consider the following: tiles is initialized using the org.apache.tiles.definition.UrlDefinitionsFactory default definitions factory.

        now, when a request receives and the tiles container is instructed to render a specific tiles definition, the following happens (the interessing parts):

            1. invoke 'Definition getDefinition(String name, TilesRequestContext tilesContext)' of UrlDefinitionFactory.
            2. from there invoke 'Definitions getDefinitions()' of UrlDefinitionFactory.
            3. if the instance attribute 'definitions' is null, from there invoke 'Definitions readDefinitions()' of UrlDefinitionFactory.

        within the third call the configuration is actually parsed and the beans/instances/what ever defined within the configuration file(s) are getting created.
        unfortunatelly the UrlDefinitionFactory does not synchronize the call to the 'Definitions readDefinitions()' method. the result is, if there are multiple request reaching the servlet container at once and there has no other request been received so long, we get into classical multithreading problematics where each thread is bothering the others and the process of creating the definitions list crashs.

        greez,

        dialsc
        consider the following: tiles is initialized using the org.apache.tiles.definition.UrlDefinitionsFactory default definitions factory.

        now, when a request receives and the tiles container is instructed to render a specific tiles definition, the following happens (the interessing parts):

            1. invoke 'Definition getDefinition(String name, TilesRequestContext tilesContext)' of UrlDefinitionFactory.
            2. from there invoke 'Definitions getDefinitions()' of UrlDefinitionFactory.
            3. if the instance attribute 'definitions' is null, from there invoke 'Definitions readDefinitions()' of UrlDefinitionFactory.

        within the third call the configuration is actually parsed and the beans/instances/what ever defined within the configuration file(s) are getting created.
        unfortunatelly the UrlDefinitionFactory does not synchronize the call to the 'Definitions readDefinitions()' method. the result is, if there are multiple request reaching the servlet container at once and there has no other request been received so long, we get into classical multithreading problematics where each thread is bothering the others and the process of creating the definitions list crashs.
        Fix Version/s 2.0.5 [ 21830 ]
        Flags [Important]
        Hide
        Dirk Alexander Schaefer added a comment -

        this is a diff between the original and the version containing the changes i think that are required in order to solve the problem.

        Show
        Dirk Alexander Schaefer added a comment - this is a diff between the original and the version containing the changes i think that are required in order to solve the problem.
        Dirk Alexander Schaefer made changes -
        Attachment UrlDefinitionsFactory.diff [ 13592 ]
        Hide
        Antonio Petrelli added a comment -

        Please attach a patch using "svn diff".
        Anyway, why did you create a new field for this use? Isn't it possible to synchronize against "definitions" field itself?

        Show
        Antonio Petrelli added a comment - Please attach a patch using "svn diff". Anyway, why did you create a new field for this use? Isn't it possible to synchronize against "definitions" field itself?
        Hide
        Dirk Alexander Schaefer added a comment -

        sorry for submitting the wrong file format. i'm not yet familiar with svn.
        i use a new field because the definitions field is subject to be null initially and in that case synchronizing on it will cause an exception.

        at least i think it will, won't it?

        Show
        Dirk Alexander Schaefer added a comment - sorry for submitting the wrong file format. i'm not yet familiar with svn. i use a new field because the definitions field is subject to be null initially and in that case synchronizing on it will cause an exception. at least i think it will, won't it?
        Hide
        Antonio Petrelli added a comment -

        Mmm... I guess you're right.
        Anyway, I think that synchronization is not the correct path to follow, since every time the "definitions" object is needed, the JVM enters a critical block (that leads to performance problem).
        I think that "readDefinitions" should be called at the end of the "init" method.

        Show
        Antonio Petrelli added a comment - Mmm... I guess you're right. Anyway, I think that synchronization is not the correct path to follow, since every time the "definitions" object is needed, the JVM enters a critical block (that leads to performance problem). I think that "readDefinitions" should be called at the end of the "init" method.
        Hide
        Dirk Alexander Schaefer added a comment -

        i totally agree with that.
        i just did not want to change more than necessary because i do not know the implementation, except for this problem but in my opinion this is something that definitely should be located at the end of the init method, yes.

        Show
        Dirk Alexander Schaefer added a comment - i totally agree with that. i just did not want to change more than necessary because i do not know the implementation, except for this problem but in my opinion this is something that definitely should be located at the end of the init method, yes.
        Antonio Petrelli made changes -
        Assignee Antonio Petrelli [ brenmcguire ]
        Hide
        Antonio Petrelli added a comment -

        Moved the call for "readDefinitions" inside the "init" method of UrlDefinitionsFactory.
        Modified the calling code accordingly.

        Dirk, can you test if everything is ok?

        Thanks

        Show
        Antonio Petrelli added a comment - Moved the call for "readDefinitions" inside the "init" method of UrlDefinitionsFactory. Modified the calling code accordingly. Dirk, can you test if everything is ok? Thanks
        Antonio Petrelli made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Antonio Petrelli added a comment -

        Issue closed due to the release of Tiles 2.0.5

        Show
        Antonio Petrelli added a comment - Issue closed due to the release of Tiles 2.0.5
        Antonio Petrelli made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Antonio Petrelli made changes -
        Flags [Patch]
        Antonio Petrelli made changes -
        Workflow Struts - editable closed status [ 44433 ] Struts - editable closed status (temporary) [ 45826 ]
        Antonio Petrelli made changes -
        Workflow Struts - editable closed status (temporary) [ 45826 ] Struts - editable closed status [ 49633 ]
        Antonio Petrelli made changes -
        Workflow Struts - editable closed status [ 49633 ] Simplified [ 53143 ]
        Jeff Turner made changes -
        Project Import Mon Feb 01 01:30:28 UTC 2010 [ 1264987828110 ]

          People

          • Assignee:
            Antonio Petrelli
            Reporter:
            Dirk Alexander Schaefer
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development