web stats
Mirth Connect 3.2.x - TcpReceiver possible threading issue - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 06-02-2016, 03:20 PM
alexr alexr is offline
What's HL7?
 
Join Date: Jun 2016
Posts: 2
alexr is on a distinguished road
Default Mirth Connect 3.2.x - TcpReceiver possible threading issue

I apologize in advanced if this is not the appropriate forum.

Please take a look at the following two code snippets taken from Mirth Connect 3.2.1 source.

Code:
public class TcpReceiver extends SourceConnector {
    @Override
    public void onStart() throws ConnectorTaskException {
        ..........
        // Create the acceptor thread
        thread = new Thread() {
            @Override
            public void run()
            {
                while (getCurrentState() == DeployedState.STARTED) {
                    StateAwareSocket socket = null;

                ..........
                }
            }
        };
        thread.start();
    }
}
Code:
public abstract class SourceConnector extends Connector {
    /**
     * Start the connector
     */
    public void start() throws ConnectorTaskException, InterruptedException {
        updateCurrentState(DeployedState.STARTING);

        if (isProcessBatch()) {
            batchAdaptorFactory.start();
        }
        onStart();

        updateCurrentState(DeployedState.STARTED);
    }
}
There appears to be a race condition between the acceptor thread started in the TcpReceiver.onStart() and the current thread. The acceptor thread is checking for DeployedState.STARTED while the current thread is trying to set it.
If the acceptor thread wins this race the result is the channel reporting it is deployed and working but not being able to establish TCP connections.
I was not able to expose this behavior with stock mirth 3.2.1 code. I was however able to get it by sleeping the current thread and giving the acceptor thread time to start. I also ran into this issue while developing a custom connector (which is why I am here to begin with) and following the pattern in TcpReceiver. My code was doing some work in the acceptor thread before the while loop so I was getting the issue pretty consistently.

I have also searched for bug reports that would hint at this problem but the closest I've found is this: https://www.mirthproject.org/communi...ad.php?t=13426
I would appreciate any feedback related to this code.
Reply With Quote
  #2  
Old 06-07-2016, 09:01 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

Thanks for the catch, I created an issue for it: MIRTH-3979

Out of curiosity, what sort of custom connector are you building?
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 06-07-2016, 11:08 AM
alexr alexr is offline
What's HL7?
 
Join Date: Jun 2016
Posts: 2
alexr is on a distinguished road
Default

I word for an LIS developer. We build some TCP-like connectors to interface with clinical analyzers for mirth v2 and I was trying to adapt them for v3.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:19 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation