<!-- 
RSS generated by JIRA (8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d) at Wed Feb 07 20:20:32 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>OpenDaylight JIRA</title>
    <link>https://jira.opendaylight.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>8.20.10</version>
        <build-number>820010</build-number>
        <build-date>22-06-2022</build-date>
    </build-info>


<item>
            <title>[NETVIRT-39] Synchronization block on Mac String that is created in local scope</title>
                <link>https://jira.opendaylight.org/browse/NETVIRT-39</link>
                <project id="10144" key="NETVIRT">netvirt</project>
                    <description>&lt;p&gt;In ElanPacketInHandler.onPacketReceived():&lt;br/&gt;
byte[] srcMac = res.getSourceMACAddress();&lt;br/&gt;
// You create a new String here&lt;br/&gt;
String macAddress = NWUtil.toStringMacAddress(srcMac); &lt;/p&gt;

&lt;p&gt;// You call setupMacFlows with the new created String&lt;br/&gt;
ElanUtils.setupMacFlows(&#8230;., macAddress)&lt;/p&gt;

&lt;p&gt;In ElanUtils.setupMacFlows():&lt;br/&gt;
synchronized (macAddress) {&lt;br/&gt;
...&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;The macAddress String that the synchronized block is using as a mutex was created locally. If the same mac value will be used in a different place or by a different thread, it will have its own reference, thus not locking anything.&lt;/p&gt;

&lt;p&gt;A naive solution will be to use String.intern() but this is a very bad practice, as illustrated here: &lt;a href=&quot;http://stackoverflow.com/questions/461896/what-is-the-most-frequent-concurrency-issue-youve-encountered-in-java/463437#463437&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://stackoverflow.com/questions/461896/what-is-the-most-frequent-concurrency-issue-youve-encountered-in-java/463437#463437&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My suggested solution is to hold a map between macAddress to Object() and synchronized on the Object.&lt;br/&gt;
Map will be created like this:&lt;br/&gt;
CacheBuilder.newBuilder().weakValues()&lt;br/&gt;
To obtain the lock, you will use:&lt;br/&gt;
Object lock = Cache.asMap().putIfAbsent(mac, new Object());&lt;/p&gt;

&lt;p&gt;Because we are using weakValues(), there is no need to remove the entries from the map, as they will be garbage collected if there is no live reference to them.&lt;/p&gt;</description>
                <environment>&lt;p&gt;Operating System: All&lt;br/&gt;
Platform: All&lt;/p&gt;</environment>
        <key id="19960">NETVIRT-39</key>
            <summary>Synchronization block on Mac String that is created in local scope</summary>
                <type id="10104" iconUrl="https://jira.opendaylight.org/secure/viewavatar?size=xsmall&amp;avatarId=10303&amp;avatarType=issuetype">Bug</type>
                                                <status id="5" iconUrl="https://jira.opendaylight.org/images/icons/statuses/resolved.png" description="A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.">Resolved</status>
                    <statusCategory id="3" key="done" colorName="green"/>
                                    <resolution id="10000">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="guy.sela@hpe.com">Guy Sela</reporter>
                        <labels>
                    </labels>
                <created>Mon, 4 Jul 2016 08:15:22 +0000</created>
                <updated>Thu, 19 Oct 2017 21:28:08 +0000</updated>
                            <resolved>Mon, 3 Apr 2017 19:40:45 +0000</resolved>
                                    <version>Boron</version>
                                                    <component>General</component>
                        <due></due>
                            <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="36210" author="alonko@hpe.com" created="Tue, 30 Aug 2016 08:50:56 +0000"  >&lt;p&gt;I think this can wait for Carbon unless Guy has objections as the problem is theoretical and exact implications are unknown&lt;/p&gt;</comment>
                            <comment id="36211" author="guy.sela@hpe.com" created="Tue, 30 Aug 2016 09:15:14 +0000"  >&lt;p&gt;First of all the problem isn&apos;t theoretical. Maybe you meant to say that it has low probability to happen because it&apos;s a timing issue, and not deterministic (as all concurrency problems are by nature).&lt;br/&gt;
I think that in order to decide what to do with this bug&apos;s priority, you need to answer the following questions:&lt;br/&gt;
1) Why are there synchronized blocks there in the first place? What are the risks of removing them? Right now the code acts like there are no synchronized block (putting memory barriers aside), because the mutex is local, but still &quot;everything works&quot;. &lt;br/&gt;
2) If there is a real reason behind the synchronized blocks, we can consider to do FOR NOW the dirty bad practice solution, and just replace every:&lt;br/&gt;
synchronized (macAddress) {&lt;br/&gt;
...&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;With: &lt;br/&gt;
synchronized (macAddress.intern()) {&lt;br/&gt;
...&lt;br/&gt;
}&lt;/p&gt;</comment>
                            <comment id="36212" author="shague@redhat.com" created="Mon, 3 Apr 2017 19:40:45 +0000"  >&lt;p&gt;&lt;a href=&quot;https://git.opendaylight.org/gerrit/#/c/50370/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://git.opendaylight.org/gerrit/#/c/50370/&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                            <customfield id="customfield_11400" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10208" key="com.atlassian.jira.plugin.system.customfieldtypes:textfield">
                        <customfieldname>External issue ID</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>6147</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10201" key="com.atlassian.jira.plugin.system.customfieldtypes:url">
                        <customfieldname>External issue URL</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[https://bugs.opendaylight.org/show_bug.cgi?id=6147]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10000" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|i01pc7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                </customfields>
    </item>
</channel>
</rss>