Mohit Sinha created FINERACT-759:
------------------------------------

             Summary: Possible thread unsafe bug for batch processing
                 Key: FINERACT-759
                 URL: https://issues.apache.org/jira/browse/FINERACT-759
             Project: Apache Fineract
          Issue Type: Bug
            Reporter: Mohit Sinha


I have noticed some errors while doing batch processing in Mifos.
 
!https://mail.google.com/mail/u/0?ui=2&ik=1a1c6fef1c&attid=0.1&permmsgid=msg-a:r-170619917994284201&th=16afe11c353a555b&view=fimg&sz=s0-l75-ft&attbid=ANGjdJ9p_KNZRnGZYdfbuosB_WlTfMEykfXgJGyi1TLe-OeGixMWmUITIPJQgNsQNC9oHaLkTi-bS1S7TPq-ogo39qUYdie-_bMiWAHXhB2ewuIgRzmoR_ga1abS6rA&disp=emb&realattid=ii_jw7o4odi1|width=1354,height=319!
I found out some reasons for this on this link 
[https://stackoverflow.com/questions/53470042/java-util-concurrentmodificationexception-bug-when-performing-io-operations]
 
Hence, the object might change when it is in the middle of Gson serialization.
 
After further studying the codebase, I found out some possible thread related 
bugs in *BatchApiServiceImpl.java.* 
It is a singleton with a variable that stores the state for a request. 
 
 
{code:java}
private List<BatchResponse> checkList = new ArrayList<>();  {code}
 
On line number 125,
 
 
{code:java}
checkList = responseList;
return responseList;  {code}
This line may cause the error.
 
There are some possible fixes for this:
 # I can remove *BatchApiServiceImpl.java* from the Spring Context and create a 
new object for every request. This will handle the possible thread related bugs.
 # In *BatchApiResource.java* line 119 

{code:java}
if (enclosingTransaction) {
 result = service.handleBatchRequestsWithEnclosingTransaction(requestList, 
uriInfo);
} else {
 result = service.handleBatchRequestsWithoutEnclosingTransaction(requestList, 
uriInfo);
}

return this.toApiJsonSerializer.serialize(result);{code}
I can clone the *result* array and then pass it for serialization. This will 
remove the error, but won't solve possible thread related bugs.
 # I can modify *checkList* logic and possibly remove it from 
*BatchApiServiceImpl.java* . 

 
I will need your suggestions and opinions on this.
 
 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to