You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by "Ravi Undupitiya (JIRA)" <ji...@apache.org> on 2016/05/20 10:50:12 UTC

[jira] [Updated] (SYNAPSE-1002) API's are dispatched in a non-deterministic manner when path segments are overlapping

     [ https://issues.apache.org/jira/browse/SYNAPSE-1002?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ravi Undupitiya updated SYNAPSE-1002:
-------------------------------------
    Attachment: api-nondeterministic-fix.diff

> API's are dispatched in a non-deterministic manner when path segments are overlapping
> -------------------------------------------------------------------------------------
>
>                 Key: SYNAPSE-1002
>                 URL: https://issues.apache.org/jira/browse/SYNAPSE-1002
>             Project: Synapse
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.1
>            Reporter: Ravi Undupitiya
>            Assignee: Hiranya Jayathilaka
>              Labels: API, Non-deterministic
>             Fix For: 2.1
>
>         Attachments: api-nondeterministic-fix.diff
>
>
> i) Create the below API
> {code}
> <?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>
> <respond />
> </inSequence>
> <outSequence />
> </resource>
> <resource methods="POST GET" uri-template="/{+username}/foo">
> <inSequence>
> <log>
> <property name="======>; foo" expression="get-property("uri.var.username")" />
> </log>
> <respond />
> </inSequence>
> <outSequence />
> </resource>
> </api>
> {code}
> 2) Send the request following and you'll get the log entry as "response, ======>; = esb" .
> curl -v http://192.168.0.105:8280/services/abc/testContext/esb -H "Content-Type: application/json" -d {} -X POST
> 3) Send the request following and you will get the log entry as "request, ======>; foo = esb"
> curl -v http://192.168.0.105:8280/services/abc/testContext/esb/foo -H "Content-Type: application/json" -d {} -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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org