[QFJ-637] QuickFixJ appears to modify headers of a message after delivery; iteration over the Header's fields on another thread produces a ConcurrentModificationException Created: 29/Sep/11  Updated: 15/Nov/11  Resolved: 15/Nov/11

Status: Closed
Project: QuickFIX/J
Component/s: Engine, Message Generation
Affects Version/s: 1.5.0, 1.5.1
Fix Version/s: None

Type: Bug Priority: Default
Reporter: Michael Guyver Assignee: Unassigned
Resolution: Not a bug Votes: 0
Labels: Concurrency, ConcurrentModificationException, QuickfixJ
Environment:

RHEL kernel 2.6.18; Sun/Oracle Java 1.6.20; QuickFixJ 1.5.1



 Description   

We have created a client to the QuickFixJ engine which implements the Application interface; in order to manage our threading we have put a thread barrier between our client Application and QuickFixJ, where its invocations of the Application API are converted into Runnable commands which are executed on the client thread. Other parts of the system interact with the client across the thread barrier in the same way and it enables the client to run in a single-threaded manner.

We log the messages we get from QuickFixJ and fairly frequently see a ConcurrentModificationException being raised when we iterate over the fields in a message's header:

Iterator<Field> iter = message.getHeader().iterator();
while (iter.hasNext())

{ // log out the values - CME is raised here }

I would have thought that a message and its header should be immutable after it has been delivered to the client Application, but it seems it is being changed on a different thread. Is this expected behaviour? Does QuickFixJ implement some sort of Message pooling?

Thanks

Michael



 Comments   
Comment by Michael Guyver [ 05/Oct/11 ]

It seems that this was being caused by the presentation of messages by QuickFixJ to the toAdmin(Message,SessionID) and toApp(Message,SessionID) methods prior to sending: in these two cases the subsequent modification of the message header is expected due to the addition of a sending-time field.

Since the thread boundary was implemented ascynchronously, it's likely that the CME was being produced by QuickFixJ adding the header while the message was being inspected. IOW, expected behaviour.

Comment by Michael Guyver [ 10/Oct/11 ]

Handling the message on the QuickFixJ server thread in the .toAdmin method would appear not to have solved the problem. We have just seen this exception while attempting to .clone() the message in order to provide an immutable message to pass to the client application:
java.util.ConcurrentModificationException
at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1100)
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1136)
at java.util.TreeMap$EntryIterator.next(TreeMap.java:1131)
at java.util.TreeMap.buildFromSorted(TreeMap.java:2372)
at java.util.TreeMap.buildFromSorted(TreeMap.java:2364)
at java.util.TreeMap.buildFromSorted(TreeMap.java:2322)
at java.util.TreeMap.putAll(TreeMap.java:296)
at quickfix.FieldMap.initializeFrom(FieldMap.java:488)
at quickfix.Message.cloneTo(Message.java:126)
at quickfix.Message.clone(Message.java:116)
[...]

Could someone suggest how QuickFixJ can realistically expect to modifiy the fields of a message while it is being processed by application code?

Comment by Michael Guyver [ 10/Oct/11 ]

Please ignore the above - the issue was caused elsewhere and not by QuickFixJ. Apologies.

Generated at Sun Apr 28 12:21:35 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.