Java DatagramSocket limit?

  • Platform information:
    • Hardware: R PI 3
    • OS: Raspian Lite
    • Java Runtime Environment: java version “1.8.0_201” or Zulu Embedded 8.25.0.76-linux
    • openHAB version: 2.4
  • Issue of the topic:

Hi Guys,

I’m fairly new with Openhab/Raspian and obviously a complete noob with Linux, been using Openhab for a few months and have learned a lot via the forums.
Everything had been working find until about 3 weeks ago when I installed WOL binding enabling google home to turn on my pc (via rules). It works for the first 20 odd minutes of restarting the PI but after a little while, if I call the command again, i get the below datagram socket error.

I’ve search everywhere and can’t seem to find a solution for it, tried both java-8 and zulu, removed the raspian GUI and unplugged the touch screen (cause I read somewhere that it could have been a resource issue) but the problem persists. Any help or ideas would be appreciated.

Thanks

==> /var/log/openhab2/openhab.log <==

2019-02-12 23:13:55.125 [ERROR] [nhab.binding.wol.internal.WolBinding] - Failed to send Wake-on-LAN packet [broadcastIp=My static IP, macaddress=My Mac Address]

java.net.SocketException: maximum number of DatagramSockets reached

	at sun.net.ResourceManager.beforeUdpCreate(ResourceManager.java:73) ~[?:?]

	at java.net.AbstractPlainDatagramSocketImpl.create(AbstractPlainDatagramSocketImpl.java:77) ~[?:?]

	at java.net.DatagramSocket.createImpl(DatagramSocket.java:337) ~[?:?]

	at java.net.DatagramSocket.<init>(DatagramSocket.java:239) ~[?:?]

	at java.net.DatagramSocket.<init>(DatagramSocket.java:196) ~[?:?]

	at org.openhab.binding.wol.internal.WolBinding.sendWolPacket(WolBinding.java:95) [237:org.openhab.binding.wol:1.13.0]

	at org.openhab.binding.wol.internal.WolBinding.receiveCommand(WolBinding.java:74) [237:org.openhab.binding.wol:1.13.0]

	at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:45) [197:org.openhab.core.compat1x:2.4.0]

	at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:82) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:166) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

You could start by putting the binding on DEBUG mode:

May we see the rules? Unlikely, but imagining looping behaviour.

Hi Ross, please see below my item and rule

Item:

Switch Computer "Computer" <switch> [ "Switchable" ] { wol="IP address#Mac address" }

rule:

rule "Turn on Monitor Power Strip When Computer turns on"
when Item Computer changed to ON
then 
MonitorsStiprPower.sendCommand(ON)
triggeringItem.sendCommand(OFF)
end

Here’s the log (finally found console …)

2019-02-13 20:32:44.996 [DEBUG] [org.eclipse.jetty.server.HttpChannel] - sendResponse info=null content=DirectByteBuffer@e85767[p=0,l=143,c=32768,r=143]={<<<event: message\nda...ommandEvent"}\n\n>>>StateEvent"}\n\ntat...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00} complete=false committing=false callback=Blocker@189e3ef{null}

2019-02-13 20:32:44.997 [DEBUG] [org.eclipse.jetty.server.session    ] - FinalSession=null old_session_manager=null this=org.eclipse.jetty.server.session.SessionHandler22240419==dftMaxIdleSec=600

2019-02-13 20:32:44.998 [DEBUG] [.eclipse.jetty.server.HttpConnection] - org.eclipse.jetty.server.HttpConnection$SendCallback@11bcc82[PROCESSING][i=null,cb=org.eclipse.jetty.server.HttpChannel$ContentCallback@1981ca1] generate: FLUSH (null,[p=0,l=143,c=32768,r=143],false)@COMMITTED

2019-02-13 20:32:44.996 [ERROR] [nhab.binding.wol.internal.WolBinding] - Failed to send Wake-on-LAN packet [broadcastIp=192.168.1.88, macaddress=4ccc6acd980e]

java.net.SocketException: maximum number of DatagramSockets reached

	at sun.net.ResourceManager.beforeUdpCreate(ResourceManager.java:73) ~[?:?]

	at java.net.AbstractPlainDatagramSocketImpl.create(AbstractPlainDatagramSocketImpl.java:77) ~[?:?]

	at java.net.DatagramSocket.createImpl(DatagramSocket.java:337) ~[?:?]

	at java.net.DatagramSocket.<init>(DatagramSocket.java:239) ~[?:?]

	at java.net.DatagramSocket.<init>(DatagramSocket.java:196) ~[?:?]

	at org.openhab.binding.wol.internal.WolBinding.sendWolPacket(WolBinding.java:95) [237:org.openhab.binding.wol:1.13.0]

	at org.openhab.binding.wol.internal.WolBinding.receiveCommand(WolBinding.java:74) [237:org.openhab.binding.wol:1.13.0]

	at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:45) [197:org.openhab.core.compat1x:2.4.0]

	at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:82) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:166) [3:org.apache.karaf.services.eventadmin:4.2.1]

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

2019-02-13 20:32:44.998 [DEBUG] [org.eclipse.jetty.server.Server     ] - handled=true async=false committed=false on HttpChannelOverHttp@1f1ea2d{r=1,c=false,a=DISPATCHED,uri=//myopenhab.org/rest/items/Computer?,age=63}

2019-02-13 20:32:45.004 [DEBUG] [clipse.jetty.server.HttpChannelState] - unhandle HttpChannelState@f174f6{s=DISPATCHED a=NOT_ASYNC i=true r=READY w=false}

2019-02-13 20:32:45.005 [DEBUG] [org.eclipse.jetty.io.ChannelEndPoint] - flushed 149 SocketChannelEndPoint@14b37ce{/192.168.1.88:53323<->/192.168.1.159:8080,OPEN,fill=-,flush=W,to=2374/30000}{io=0/0,kio=0,kro=1}->HttpConnection@42a2c3[p=HttpParser{s=END,0 of -1},g=HttpGenerator@d4aa3f{s=COMMITTED}]=>HttpChannelOverHttp@1e80cfb{r=5,c=true,a=ASYNC_WAIT,uri=//192.168.1.159:8080/rest/events,age=3073951}

2019-02-13 20:32:45.006 [DEBUG] [org.eclipse.jetty.server.HttpChannel] - HttpChannelOverHttp@1f1ea2d{r=1,c=false,a=COMPLETING,uri=//myopenhab.org/rest/items/Computer?,age=71} action COMPLETE

2019-02-13 20:32:45.006 [DEBUG] [org.eclipse.jetty.io.WriteFlusher   ] - Flushed=true written=149 remaining=0 WriteFlusher@1c5f7ac{WRITING}->null

2019-02-13 20:32:45.008 [DEBUG] [org.eclipse.jetty.server.HttpChannel] - sendResponse info=null content=HeapByteBuffer@1488d3e[p=0,l=0,c=0,r=0]={<<<>>>} complete=true committing=true callback=Blocker@c0fc9e{null}

2019-02-13 20:32:45.008 [DEBUG] [.eclipse.jetty.server.HttpConnection] - org.eclipse.jetty.server.HttpConnection$SendCallback@11bcc82[PROCESSING][i=null,cb=org.eclipse.jetty.server.HttpChannel$ContentCallback@1981ca1] generate: DONE (null,[p=143,l=143,c=32768,r=0],false)@COMMITTED

2019-02-13 20:32:45.009 [DEBUG] [org.eclipse.jetty.server.HttpChannel] - COMMIT for /rest/items/Computer on HttpChannelOverHttp@1f1ea2d{r=1,c=true,a=COMPLETING,uri=//myopenhab.org/rest/items/Computer?,age=74}

200 OK HTTP/1.1

Content-Type: text/plain

2019-02-13 20:32:45.011 [DEBUG] [org.eclipse.jetty.server.HttpChannel] - sendResponse info=null content=DirectByteBuffer@e85767[p=0,l=139,c=32768,r=139]={<<<event: message\nda...mStateEvent"}\n\n>>>"}\n\nStateEvent"}\n...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00} complete=false committing=false callback=Blocker@189e3ef{null}

2019-02-13 20:32:45.011 [DEBUG] [.eclipse.jetty.server.HttpConnection] - org.eclipse.jetty.server.HttpConnection$SendCallback@3866b5[PROCESSING][i=HTTP/1.1{s=200,h=1,cl=-1},cb=org.eclipse.jetty.server.HttpChannel$CommitCallback@77a647] generate: NEED_HEADER (null,[p=0,l=0,c=0,r=0],true)@START

2019-02-13 20:32:45.012 [DEBUG] [org.eclipse.jetty.http.HttpGenerator] - generateHeaders HTTP/1.1{s=200,h=1,cl=-1} last=true content=HeapByteBuffer@1488d3e[p=0,l=0,c=0,r=0]={<<<>>>}

2019-02-13 20:32:45.013 [DEBUG] [.eclipse.jetty.server.HttpConnection] - org.eclipse.jetty.server.HttpConnection$SendCallback@11bcc82[PROCESSING][i=null,cb=org.eclipse.jetty.server.HttpChannel$ContentCallback@fc61ae] generate: FLUSH (null,[p=0,l=139,c=32768,r=139],false)@COMMITTED

2019-02-13 20:32:45.014 [DEBUG] [org.eclipse.jetty.http.HttpGenerator] - Content-Type: text/plain

2019-02-13 20:32:45.015 [DEBUG] [org.eclipse.jetty.http.HttpGenerator] - CONTENT_LENGTH

2019-02-13 20:32:45.017 [DEBUG] [.eclipse.jetty.server.HttpConnection] - org.eclipse.jetty.server.HttpConnection$SendCallback@3866b5[PROCESSING][i=HTTP/1.1{s=200,h=1,cl=-1},cb=org.eclipse.jetty.server.HttpChannel$CommitCallback@77a647] generate: FLUSH ([p=0,l=97,c=8192,r=97],[p=0,l=0,c=0,r=0],true)@COMPLETING

2019-02-13 20:32:45.017 [DEBUG] [org.eclipse.jetty.io.ChannelEndPoint] - flushed 145 SocketChannelEndPoint@14b37ce{/192.168.1.88:53323<->/192.168.1.159:8080,OPEN,fill=-,flush=W,to=10/30000}{io=0/0,kio=0,kro=1}->HttpConnection@42a2c3[p=HttpParser{s=END,0 of -1},g=HttpGenerator@d4aa3f{s=COMMITTED}]=>HttpChannelOverHttp@1e80cfb{r=5,c=true,a=ASYNC_WAIT,uri=//192.168.1.159:8080/rest/events,age=3073962}

2019-02-13 20:32:45.019 [DEBUG] [org.eclipse.jetty.io.WriteFlusher   ] - Flushed=true written=145 remaining=0 WriteFlusher@1c5f7ac{WRITING}->null

Okeydoke, this rule waits for Computer to go ON and then immediately commands it OFF. That seems odd, but won’t trigger WoL.

So … what turns Computer ON?
Have you looked in events.log?

Hi, the Computer item is shared with google home, voice is the trigger.

I think the rule is working fine thou

2019-02-13 22:22:22.807 [vent.ItemStateChangedEvent] - Computer changed from OFF to ON

2019-02-13 22:22:23.240 [ome.event.ItemCommandEvent] - Item 'MonitorsStiprPower' received command ON

2019-02-13 22:22:23.244 [ome.event.ItemCommandEvent] - Item 'Computer' received command OFF

2019-02-13 22:22:23.249 [nt.ItemStatePredictedEvent] - MonitorsStiprPower predicted to become ON

2019-02-13 22:22:23.255 [vent.ItemStateChangedEvent] - Computer changed from ON to OFF

Okay, if you are sure you are not seeing many Computer ON activity in events.log, we can rule out looping triggers for WoL binding.

yeap, it’s just turns on, and power up the powerboard for the monitors at the same time, then turn the “computer” switch to off allowing for the next time i want to use it.
so frustrating that it only works after a reboot of openhab. I’ve read a lot of posts about socket errors and still feeling like i know nothing lol. way over my head.

Did you mange to get this fixed? My WOL was working flawlessly on 2.3. After upgrading to 2.4 I’m getting the maximum number of DatagramSockets reached as well.

Hi,

I didn’t managed to get it fixed but ended up using a different approach for it to work by exec a wake on lan command through Linux. (thou I have since moved from Openhab… )

Mail](https://go.microsoft.com/fwlink/?LinkId=550986) for Windows 10

Ah ok…What did you move to?

I also ended up using the executeCommandLine option using rules. Messy …but works…