[QFJ-969] Thread Safety FileStore.set Created: 28/Jan/19  Updated: 28/Jan/19

Status: Open
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 2.1.0
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Yanick Salzmann Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: Message, QuickfixJ


 Description   

When seeking for optimizations for file sync I have come across the FileStore.set method and was wondering about its thread safety. I labelled this issue as improvement, because I am not sure if it is maybe already been taken care of somewhere else, however lets look at this method:

https://github.com/quickfix-j/quickfixj/blob/045be5c09f872b1bf7b1a8ed2904efd0030c59bd/quickfixj-core/src/main/java/quickfix/FileStore.java#L364

As you can see, at the very beginning of the function the offset inside the RandomAccessFile is taken as the message offset. The actual writing of the information happens after many more instructions, one of them even including a synchronization on a file descriptor.

According to my understanding the offset obtained on line 365 could easily be outdated by the time the message is written at line 377. Of course it is possible, that synchronization is supposed to be happening outside of the set method, however I do not see any contract enforcing this in MessageStore.set.

Should this method not be thread safe to avoid potential data inconsitencies?



 Comments   
Comment by Christoph John [ 28/Jan/19 ]

Hi Yanick Salzmann,

as far as I am aware the MessageStore.set() method is only accessed from Session.sendRaw() where it is guarded by a lock. But yeah, in theory it could happen that it is accessed concurrently. It seems like this could happen especially on shutdown. See QFJ-762.
There is another issue QFJ-552 which provides a wrapper around a MessageStore that one could use.

Cheers,
Chris.

Generated at Mon May 06 15:42:18 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.