]
Christian von Kutzleben commented on JBTM-2394:
-----------------------------------------------
Hi Tom,
My interpretation of JTA 1.0.1, section 3.4.3 is a bit different from yours:
IMO it focuses on "Different Java threads may be using the same connection resource
to access the
resource manager if the connection spans multiple method invocation." and not on
"threads, XAResources, anything goes!"
It does not specifically advocate that the current transaction reaper implementation is a
viable approach.
We can synchronize access to the connection currently associated with this XAResource,
however then the
transaction reaper thread can't do it's job. This change would be spec-compliant,
the RPC protocol would
not get corrupted, still, the reaper would not work.
Transaction Reaper "abuses" in-use connection, leading to
RPC protocol corruption
---------------------------------------------------------------------------------
Key: JBTM-2394
URL:
https://issues.jboss.org/browse/JBTM-2394
Project: JBoss Transaction Manager
Issue Type: Bug
Reporter: Christian von Kutzleben
Assignee: Tom Jenkinson
The scenario is as follows:
An regular JBoss application thread uses the connection associated with an XAResource for
it's work with the database backend. Start(xid) had been invoked, which means, the
associated connection is "switched" to that xid. After finishing work, the
regular JBoss application thread would eventually call end(xid, TMSUCCESS).
The application executes a query that takes longer than the configured timeout.
The work with the database is done via database specific RPC invocations, caused by a
enterprise bean (which uses the JPA API and the JPA implementation eventually talks to the
database via the database protocol).
The (lower-level) connection is a TCP/IP connection, and
the RPC protocol if of the form: "send data to server, then wait for server
reply"
At this point it should be clear, that the TCP/IP connection should not be shared by
another thread whilst in the middle of an RPC invocation, because neither does the
database server expect any data at this moment on this particular TCP/IP connection nor
does it work, that then 2 threads wait on the same socket to receive a reply. (E.g. a
ClosedByInterruptException is likely, there might be other error though, depending how
wrong data is interpreted, e.g. BufferUnderflowException).
Unfortunately, this is exactly the behavior of the JBoss "Transaction Reaper"
thread, that uses the very same XAResource, that had been used by the regular JBoss
application thread and is currently associated to a connection, "switched" to
the current xid.
By definition of the XA specification, any other XAResource could be used to terminate
that transaction branch, and it would be fine, if the transaction reaper thread would use
any XAResource (regular one, or one from our recovery module) to do that.
This is a conceptual flaw of the transaction reaper implementation, and we can't
implement a workaround (except extremely silly things like reaper thread recognition by
comparing thread names ...)
We could synchronize access to the TCP/IP connection, to not allow another thread
communication, while another thread is active doing so, however, that kind of defeats the
purpose of the reaper thread, as it would be blocked indefinitely.