Closing and opening a new connection immediately afterwards leads to IOException
0-27 22:35:06.813 10452-10684/se.leap.bitmaskclient.beta W/System.err: go.Universe$proxyerror: failed to listen: listen tcp 127.0.0.1:4430: bind: address already in use
10-27 22:35:06.813 10452-10684/se.leap.bitmaskclient.beta W/System.err: at shapeshifter.ShapeShifter.open(Native Method)
10-27 22:35:06.813 10452-10684/se.leap.bitmaskclient.beta W/System.err: at se.leap.bitmaskclient.pluggableTransports.Shapeshifter.start(Shapeshifter.java:66)
10-27 22:35:06.813 10452-10684/se.leap.bitmaskclient.beta W/System.err: at de.blinkt.openvpn.core.OpenVPNService.startOpenVPN(OpenVPNService.java:401)
10-27 22:35:06.813 10452-10684/se.leap.bitmaskclient.beta W/System.err: at de.blinkt.openvpn.core.OpenVPNService.lambda$xqV706KOXBrcOTsqawwiDFEM26M(OpenVPNService.java)
10-27 22:35:06.813 10452-10684/se.leap.bitmaskclient.beta W/System.err: at de.blinkt.openvpn.core.-$$Lambda$OpenVPNService$xqV706KOXBrcOTsqawwiDFEM26M.run(lambda)
10-27 22:35:06.813 10452-10684/se.leap.bitmaskclient.beta W/System.err: at java.lang.Thread.run(Thread.java:856)
The error exception states that the connection was not closed when shapeshifter's open() method was called. Even though close() was called before open();
The described error occurs if the user switches back and forth between plain openvpn and a pluggable transports connection using the switch in the navigation drawer. It also occurs if the user restarts a PT connection immediately after stopping it. As a result, the port keeps being in use. Only killing the app allows the user to start a PT connection again.
A solution to this problem could be to set socket options with the help of this https://github.com/libp2p/go-reuseport