Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HL7v2 - Cannot configure MLLP client connection timeout, when created from DefaultHapiContext #126

Open
patrick-vachon-smilecdr opened this issue Jun 20, 2024 · 1 comment

Comments

@patrick-vachon-smilecdr

On Hapi-base 2.5.1
When using ca.uhn.hl7v2.DefaultHapiContext.newClient(), it ends up creating a Socket that is not using a connection timeout:

	at ca.uhn.hl7v2.app.ConnectionFactory.createSocket(ConnectionFactory.java:77)
	at ca.uhn.hl7v2.app.ConnectionFactory.openEagerly(ConnectionFactory.java:53)
	at ca.uhn.hl7v2.app.ConnectionFactory.open(ConnectionFactory.java:44)
	at ca.uhn.hl7v2.app.ConnectionHub$1.open(ConnectionHub.java:99)
	at ca.uhn.hl7v2.app.ConnectionHub$1.open(ConnectionHub.java:85)
	at ca.uhn.hl7v2.app.ConnectionHub$CountingMap.put(ConnectionHub.java:489)
	at ca.uhn.hl7v2.app.ConnectionHub.attach(ConnectionHub.java:121)
	at ca.uhn.hl7v2.app.ConnectionHub.attach(ConnectionHub.java:260)
	at ca.uhn.hl7v2.DefaultHapiContext.newClient(DefaultHapiContext.java:335)

It would be great to be able to configure it somehow, easily.

class ConnectionFactory
    ...
    private static Socket createSocket(ca.uhn.hl7v2.util.SocketFactory socketFactory, String host, int port, boolean tls)
        throws IOException {
        Socket socket;
        if (tls) {
            socket = socketFactory.createTlsSocket();
        } else {
            socket = socketFactory.createSocket();
        }
->      socket.connect(new InetSocketAddress(host, port));
        return socket;
    }

as Socket has a connect() method on which we can pass a connection timeout.
May be it could be added in ca.uhn.hl7v2.util.SocketFactory and used with the appropriate Socket.connect()?

Was found with

        <dependency>
            <groupId>ca.uhn.hapi</groupId>
            <artifactId>hapi-structures-v24</artifactId>
            <version>2.5.1</version>
        </dependency>

Culprit code on master:
https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-base/src/main/java/ca/uhn/hl7v2/app/ConnectionFactory.java

Thanks!

@michaelabuckley
Copy link

If you add a timeout to the ConnectionData, you could configure it when building the ConnectionHub. That is passed all the way down to the ConnectionFactory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants