BUG-7901: fix unsynchronized transaction access 38/54538/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Mar 2017 15:29:16 +0000 (17:29 +0200)
committerAnil Vishnoi <vishnoianil@gmail.com>
Fri, 7 Apr 2017 22:51:56 +0000 (22:51 +0000)
commitc7c10dfc36437fdf724f3ae6515cfe9478b7408d
tree1aceb4b15b5f3afcf6eb7e8773a19f78e1f9450c
parent326e82a9d6fa7f25579157b3bd0c20b421a0d14e
BUG-7901: fix unsynchronized transaction access

The evidence in the issue indicates that we have a race condition
where a batch of modifications is being submitted (triggered by
a write/delete and exceeded batch count) and we are observing a
concurrent modification. After auditing the CDS side of this, while
we can improve safety a bit, the scenario has to involve multi-threaded
access by the client.

Looking at TransactionChainManager, it seems to be heavily synchronized,
but there is a hole in the paths which are using getTransactionSafely().

While the access to the TransactionChain, it returns the transaction
(which really is an alias to the wTx field). That throws of static
analysis, as we end up the object pointed to by wTx without holding
the lock -- hence concurrent threads will end up touching the transaction
without any guards, leading to a violation of Transaction contract (which
requires external synchronization).

This patch reworks getTransactionSafely() so it only ensures the field
is initialized as appropriate and makes its callers access the wTx field
with the proper lock held.

Bug: 7500
Bug: 7901
Bug: 8060
Change-Id: I058feb55f91a40ccda6d69ee87cd1a20f792afba
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 6dbbd412a88dafdb7d7acd824516850b473b145f)
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManager.java