Uploaded image for project: 'Synapse'
  1. Synapse
  2. SYNAPSE-1002

API's with overlapping path segments are dispatched in a non-deterministic manner when they are updated

    XMLWordPrintableJSON

Details

    • Patch

    Description

      i) Create the below API

      <?xml version="1.0" encoding="UTF-8"?>
      <api name="testAPI" context="/services/abc/testContext">
          <resource methods="POST GET" uri-template="/{+username}">
              <inSequence>
                       <log>
                                <property name="======>;" expression="get-property("uri.var.username")" />
                       </log>
                       <header name="To" action="remove"/>
                       <property name="RESPONSE" value="true" scope="default" type="STRING"/>
                       <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
                       <send/>
              </inSequence>
              <outSequence />
          </resource>
          <resource methods="POST GET" uri-template="/{+username}/foo">
              <inSequence>
                      <log>
                              <property name="======>; foo" expression="get-property("uri.var.username")" />
                      </log>
                       <header name="To" action="remove"/>
                       <property name="RESPONSE" value="true" scope="default" type="STRING"/>
                       <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
                       <send/>
              </inSequence>
              <outSequence />
          </resource>
      </api>
      

      2) Send the request following and you'll get the log entry as "response, ======>; = esb" .

      curl -v http://localhost:8280/services/abc/testContext/esb -H "Content-Type: application/xml" -d '<abc/>' -X POST

      3) Send the request following and you will get the log entry as "request, ======>; foo = esb"

      curl -v http://localhost:8280/services/abc/testContext/esb/foo -H "Content-Type: application/xml" -d '<abc/>' -X POST

      4) Update one of the resources.

      5) Note that the resource selection behavior is not deterministic.

      This non-deterministic dispatching can be an issue and it is happening due to the use of a Set as the collection that holds resources. To fix this issue we can use an ordered set like SortedSet however this provides log(n) time for add operations and since this set is created for every request, a better solution is to use LinkedHashSet which has better performance. However LinkedHashSet will only guarantee insertion order (so if the resources are swapped in the configuration, we will again see a different behavior).

      A similar fix has been done to maintain resource ordering by using LinkedHashMap which also only guarantees insertion order.

      Based on this, I've attach a diff that uses a LinkedHashSet to overcome this issue.

      Attachments

        1. api-nondeterministic-fix.diff
          0.7 kB
          Ravi Undupitiya

        Activity

          People

            hiranya Hiranya Kasub Jayathilaka
            raviu Ravi Undupitiya
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: