calimero-project / calimero-core

Core library for KNX network access and management
Other
128 stars 65 forks source link

KNXNetworkLinkIP leaks threads if it cannot connect #57

Closed sjsf closed 6 years ago

sjsf commented 6 years ago

The KNXNetworkLinkIP class leaks threads in case it cannot connect:

image

The corresponding stacktrace:

16:03:31.705 ERROR tuwien.auto.calimero[:46] - KNXnet/IP Tunneling 10.42.0.13:3671: communication failure on connect
java.net.BindException: Can't assign requested address (Bind failed)
    at java.net.PlainDatagramSocketImpl.bind0(Native Method)
    at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:93)
    at java.net.DatagramSocket.bind(DatagramSocket.java:392)
    at java.net.DatagramSocket.<init>(DatagramSocket.java:242)
    at tuwien.auto.calimero.knxnetip.ClientConnection.connect(ClientConnection.java:150)
    at tuwien.auto.calimero.knxnetip.KNXnetIPTunnel.<init>(KNXnetIPTunnel.java:131)
    at tuwien.auto.calimero.link.KNXNetworkLinkIP.<init>(KNXNetworkLinkIP.java:142)
        ...

According to what I understood, the super() constructor already spawns the EventNotifier thread and when establishing the KNXnetIPConnection fails down the road, it misses to close the notifier thread.

I observed this behavior in calimero-core 2.3, but if I'm not mistaken it hasn't change in the current master branch.

bmalinowsky commented 6 years ago

Yes, thanks for pointing that out! The other AbstractLink constructor was actually intended for that.