tcpServer socket unable to close properly when reloaded

2,079 views
Skip to first unread message

Walter Chang

unread,
Jul 7, 2015, 6:26:55 AM7/7/15
to chromi...@chromium.org
i have an app that open a tcpServer socket to listen to incoming request.  everything works as advertised until i tried to reload the app, the server socket is not released properly and i get "error listening: net::ERR_ADDRESS_IN_USE".  

i tried to close the connection when chrome.runtime.onSuspend is fired but onSuspend was never fired!!

then i did successfully call
1. chrome.sockets.tcpServer.onAccept.removeListener()
2. chrome.sockets.tcpServer.disconnect()
3. chrome.sockets.tcpServer.close()
when the main window is closed but when i reload, the same ERR_ADDRESS_IN_USE error is raised.

the only thing i can do to unbind the socket is to disable it.

what is preventing the listening port from closing?

btw, i am on dev channel.

Reilly Grant

unread,
Jul 7, 2015, 2:24:21 PM7/7/15
to Walter Chang, chromi...@chromium.org
When you "reload" the app are you closing and re-opening the app window or are you clicking the "Reload" button on chrome://extensions? In the former case you should be able to reliably close the socket from the background page if you listen for a window close event. In the later case the app is being forcibly shut down and the TCP socket will be closed by Chrome but it is possible the host OS is preventing the port from being reused for a short period of time. Can you provide a demo app that exhibits this behavior?

--
You received this message because you are subscribed to the Google Groups "Chromium Apps" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-app...@chromium.org.
To post to this group, send email to chromi...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-apps/.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Walter Chang

unread,
Jul 7, 2015, 8:36:44 PM7/7/15
to Reilly Grant, chromi...@chromium.org

Thanks for the reply, and yes, the socket was released after a delay.  Does this have something to do with the socket reuse option and is there any way to set it?

BTW, do I need to close the socket after disconnect?

Reilly Grant

unread,
Jul 8, 2015, 8:53:29 PM7/8/15
to Walter Chang, chromi...@chromium.org
There's unfortunately no way to set the SO_REUSEADDR option on a socket through this API.

You should close the socket after disconnect as this frees the resource within Chrome.

Валерий Игоревич

unread,
Jun 26, 2019, 2:55:25 AM6/26/19
to Chromium-Apps-Announce
I have the same issue on windows 10. Increasing dynamic ports helps me.
Try to do like this:

netsh int ipv4 show dynamicport tcp
netsh int ipv4 set dynamicport tcp start=11000 num=1000
 
And the same for ipv6 and udp protocol.

вторник, 7 июля 2015 г., 13:26:55 UTC+3 пользователь Walter Chang написал:
Reply all
Reply to author
Forward
0 new messages