Re: Question Regarding McastServiceImpl#setupSocket

2019-05-30 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Gurkan,

On Thursday, May 30th, 2019, Gurkan Erdogdu
 wrote:
> 
> In  macOS test server, when configuring the mcastBindAddress as 
> 192.168.1.139 and address as 228.0.0.4 , the code does not use 
> mcastBindAddress , instead it uses multicast  address for socket
> binding and throws exception when sending the datagram packet. Here
> is the exception:
> 
> Exception in thread "main"
> org.apache.catalina.tribes.ChannelException: java.io.IOException:
> Can't assign requested address (sendto failed); No faulty members
> identified. at
> org.apache.catalina.tribes.group.ChannelCoordinator.internalStart(Chan
nelCoordinator.java:207)
>
> 
at
org.apache.catalina.tribes.group.ChannelCoordinator.start(ChannelCoordin
ator.java:111)
> at
> org.apache.catalina.tribes.group.ChannelInterceptorBase.start(ChannelI
nterceptorBase.java:165)
>
> 
at
org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor
.start(MessageDispatchInterceptor.java:228)
> at
> org.apache.catalina.tribes.group.ChannelInterceptorBase.start(ChannelI
nterceptorBase.java:165)
>
> 
at
org.apache.catalina.tribes.group.GroupChannel.start(GroupChannel.java:48
3)
> at test.MemberShipTest.main(MemberShipTest.java:44) Caused by:
> java.io.IOException: Can't assign requested address (sendto
> failed) at java.net.PlainDatagramSocketImpl.send(Native Method) at
> java.net.DatagramSocket.send(DatagramSocket.java:693) at
> org.apache.catalina.tribes.membership.McastServiceImpl.send(McastServi
ceImpl.java:505)
>
> 
at
org.apache.catalina.tribes.membership.McastServiceImpl.send(McastService
Impl.java:482)
> at
> org.apache.catalina.tribes.membership.McastServiceImpl.start(McastServ
iceImpl.java:268)
>
> 
at
org.apache.catalina.tribes.membership.McastService.start(McastService.ja
va:289)
> at
> org.apache.catalina.tribes.group.ChannelCoordinator.internalStart(Chan
nelCoordinator.java:196)
>
> 
... 6 more
> 
> When I changed the address to mcastBindAddress while creating the
> socket, no more exception occurred.

I wonder if the problem is that everyone uses multicast on Linux (or
Windows?) and nobody noticed that the code was wrong for the
non-Linux(/Windows?) case. There is this note in setupSocket:

203 if (mcastBindAddress != null) {
204 try {
205 log.info(sm.getString("mcastServiceImpl.bind",
address, Integer.toString(port)));
206 socket = new MulticastSocket(new
InetSocketAddress(address,port));
207 } catch (BindException e) {
208 /*
209  * On some platforms (e.g. Linux) it is not possible
to bind
210  * to the multicast address. In this case only bind to t
he
211  * port.
212  */
213 log.info(sm.getString("mcastServiceImpl.bind.failed"));
214 socket = new MulticastSocket(port);
215 }
216 } else {
217 socket = new MulticastSocket(port);
218 }

So either nobody ever sets the mcastBindAddress, or nobody uses a
system where is actually uses that address.

I'd accept the patch as proposed, or a PR with your name on it, but I
don't have a good place to test it in other environments. Can you file
a BZ issue or make a pull-request with your changes? Others with
better familiarity with the multicast clustering can give it a better
review.

Could you write a unit-test for it?

- -chris
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlzwHWQACgkQHPApP6U8
pFgHkxAAxqNGrVLq6G0NahXhKSYLcyF9X5OGv0bMjqg7DjFyOqAJK5X4NKpCqgox
6QUZRoS+3GWMv+uJYd8nQvV3/UBOFboD7NqKnrvgPOSTIG4IPCgp18aLec6+7W/C
mb9DfPqiANVKim5TxY7a+XctNYyN+3Rh0Zxy60SRnR4qJBzztbHBKBJlSHLgwNiG
/LGhmYlDbtOFQVuYOji4CRP3y4XnQ6LvhVLhwsbZ2q+NS0G5u2iQH3wo1fqbbFcQ
InKL2rFQJUBRQOla2f6nF8moedeEFtGbr19N8+2PqJPLJUmiBWkJhjepl/PBMvT8
rT1XUtfYMYUzByD1QwZI9SnX+HpwWn32uTue369+wsAzXMULwwlDgIuGVhIog5CV
UmU2MKWGpglWCWJK0UejV5xkhjzsdLxJD2a6RrNY8y683dL/PqwppGyGxI6uo9Ja
9Qe6MpM+qvAZHp1/7hB+KgH03HmLxXRBSl2DZbcVjmmQGhKTh3AHiI/D/8mrk8Ny
YqmkmWNTt4gTBPP9A3OQJYTsbV3MQBsLqyheYHquaHiLVdOsN9bfrXNfAV3bk9Ni
lxOE4LjAHwpXRALwtD+i3E1wGCjfeAqwMYxxZyHZGU6HXrQynQJITb11rhwo+NUN
y1615lCjNw076+bv67w3H4tjc8eewsNGPU5+8Uipq+2iXfe/pVU=
=f3l5
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: Question Regarding McastServiceImpl#setupSocket

2019-05-30 Thread Gurkan Erdogdu
 Hi ChrisIn  macOS test server, when configuring the mcastBindAddress as 
192.168.1.139 and address as 228.0.0.4 , the code does not use mcastBindAddress 
, instead it uses multicast  address for socket binding and throws exception 
when sending the datagram packet. Here is the exception:
Exception in thread "main" org.apache.catalina.tribes.ChannelException: 
java.io.IOException: Can't assign requested address (sendto failed); No faulty 
members identified.
    at 
org.apache.catalina.tribes.group.ChannelCoordinator.internalStart(ChannelCoordinator.java:207)
    at 
org.apache.catalina.tribes.group.ChannelCoordinator.start(ChannelCoordinator.java:111)
    at 
org.apache.catalina.tribes.group.ChannelInterceptorBase.start(ChannelInterceptorBase.java:165)
    at 
org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor.start(MessageDispatchInterceptor.java:228)
    at 
org.apache.catalina.tribes.group.ChannelInterceptorBase.start(ChannelInterceptorBase.java:165)
    at 
org.apache.catalina.tribes.group.GroupChannel.start(GroupChannel.java:483)
    at test.MemberShipTest.main(MemberShipTest.java:44)
Caused by: java.io.IOException: Can't assign requested address (sendto failed)
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(DatagramSocket.java:693)
    at 
org.apache.catalina.tribes.membership.McastServiceImpl.send(McastServiceImpl.java:505)
    at 
org.apache.catalina.tribes.membership.McastServiceImpl.send(McastServiceImpl.java:482)
    at 
org.apache.catalina.tribes.membership.McastServiceImpl.start(McastServiceImpl.java:268)
    at 
org.apache.catalina.tribes.membership.McastService.start(McastService.java:289)
    at 
org.apache.catalina.tribes.group.ChannelCoordinator.internalStart(ChannelCoordinator.java:196)
    ... 6 more
When I changed the address to mcastBindAddress while creating the socket, no 
more exception occurred.Regards.Gurkan
On Thursday, May 30, 2019, 5:56:46 PM GMT+3, Christopher Schultz 
 wrote:  
 
 -BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Gurkan,

On 5/29/19 02:28, Gurkan Erdogdu wrote:
> Hi In an McastServiceImpl#setupSocket method, if the user
> configures the mcastBindAddress, it will use the socket to bind to
> this address. But, in the code below, it uses the "address" field
> while creating the socket. Is this correct ?
> 
> if (mcastBindAddress != null) { try { 
> log.info(sm.getString("mcastServiceImpl.bind", address, 
> Integer.toString(port))); socket = new MulticastSocket(new 
> InetSocketAddress(address,port)); } catch (BindException e) {

That definitely does look weird.

The constructor for McastServiceImpl is even more strange:

    /**
    * @param bind - the bind address (not sure this is used yet)
    * @param mcastAddress - the mcast address
    */
    public McastServiceImpl([...],
        InetAddress bind,
        InetAddress mcastAddress,
        [...])
    throws IOException {
        [...]
        this.address = mcastAddress;
        this.mcastBindAddress = bind;
        [...]
    }

There are two items, here:

1. An address to bind to (locally)
2. A multicast target address

The constructor takes these two and calls them:

1. bind
2. mcastAddress

But the class members are called:

1. mcastBindAddress
2. address

The mcastBindAddress appears to be ignored in all but one place, where
the socket's interface is changed to it at McastServiceImpl.java:223:

220    if (mcastBindAddress != null) {
221        if(log.isInfoEnabled())
222            log.info(sm.getString("mcastServiceImpl.setInterface",
mcastBindAddress));
223        socket.setInterface(mcastBindAddress);
224    } //end if

I don't know enough about multicast to know what is supposed to be
happening, here. AFAIK, mcast is a broadcast mechanism and so there is
no difference between the "target" address and the "bind" address: you
just throw packets at the interface:port and that's that.

The code could probably use some clean-up, or at least some better
in-code documentation by someone who has a good understanding of the
whole situation.

- -chris
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlzv7ysACgkQHPApP6U8
pFjuNg/8DkSdnsKkoTmGS1N37IXVcdj5cyHlmPC+BdP3NWE4oky0j5uFrGUqcaRG
UJLsPMvtZwgSaQ/wxgin4maluAmK77Agt76r6tXJNbbpdglXVyz7ONWO8a5xmk9R
ltqLWnHVw4a/HB5vatxFgqWWc6L1qWnocJL7/sWUn1M9y9Ee43/+h5OYnaBn9bCM
R1jqVhZAodC2k1eD3HXedCMaVIA4k2fZF+TteOHNu2rDr01mJVZzPjNJ/zy4sNg7
L0P0uuqCp3ylh563c3t+slL/9XFoVDNytD46qJlmDDcOYczNjf5An6dyWBJEX348
d0FdWOw5h45lJKhMd1L9WNLymxj3gQ9a3okfhiEqyunsZA4SbMNCPgy4an8tzBsd
HsX1dNgD6P8aoy2umG6SvqgAoPb0mZxlVVT1NdbXN0uybdv/mUJgjDHNsbaCYOxG
UNBfT/p5VQxURhRuNqHsFYvHtA6pxt8mZBbwsHC6b/uOYgPXPrLbM4oQztF2YEzI
RDOr2kmA+JbEj5qKOeQa3BVGT5bUeLRWH+fDFiXq6ubdBdvHAifPJyGdYgAFLvZq
jm85WJJeNvluwB602JUJ/FFxCYe6sKL7jaqfZJClqZrscUDxve0Fckh9xLrQ/il2
0W1VqfxuWeFL6P0SgJOr7aZxbdA293o1/X10E9o6sMuWoCtHfk8=
=jSBA
-END PGP SIGNATURE-

Re: Question Regarding McastServiceImpl#setupSocket

2019-05-30 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Gurkan,

On 5/29/19 02:28, Gurkan Erdogdu wrote:
> Hi In an McastServiceImpl#setupSocket method, if the user
> configures the mcastBindAddress, it will use the socket to bind to
> this address. But, in the code below, it uses the "address" field
> while creating the socket. Is this correct ?
> 
> if (mcastBindAddress != null) { try { 
> log.info(sm.getString("mcastServiceImpl.bind", address, 
> Integer.toString(port))); socket = new MulticastSocket(new 
> InetSocketAddress(address,port)); } catch (BindException e) {

That definitely does look weird.

The constructor for McastServiceImpl is even more strange:

/**
 * @param bind - the bind address (not sure this is used yet)
 * @param mcastAddress - the mcast address
 */
public McastServiceImpl([...],
InetAddress bind,
InetAddress mcastAddress,
[...])
throws IOException {
[...]
this.address = mcastAddress;
this.mcastBindAddress = bind;
[...]
}

There are two items, here:

1. An address to bind to (locally)
2. A multicast target address

The constructor takes these two and calls them:

1. bind
2. mcastAddress

But the class members are called:

1. mcastBindAddress
2. address

The mcastBindAddress appears to be ignored in all but one place, where
the socket's interface is changed to it at McastServiceImpl.java:223:

220 if (mcastBindAddress != null) {
221 if(log.isInfoEnabled())
222 log.info(sm.getString("mcastServiceImpl.setInterface",
mcastBindAddress));
223 socket.setInterface(mcastBindAddress);
224 } //end if

I don't know enough about multicast to know what is supposed to be
happening, here. AFAIK, mcast is a broadcast mechanism and so there is
no difference between the "target" address and the "bind" address: you
just throw packets at the interface:port and that's that.

The code could probably use some clean-up, or at least some better
in-code documentation by someone who has a good understanding of the
whole situation.

- -chris
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlzv7ysACgkQHPApP6U8
pFjuNg/8DkSdnsKkoTmGS1N37IXVcdj5cyHlmPC+BdP3NWE4oky0j5uFrGUqcaRG
UJLsPMvtZwgSaQ/wxgin4maluAmK77Agt76r6tXJNbbpdglXVyz7ONWO8a5xmk9R
ltqLWnHVw4a/HB5vatxFgqWWc6L1qWnocJL7/sWUn1M9y9Ee43/+h5OYnaBn9bCM
R1jqVhZAodC2k1eD3HXedCMaVIA4k2fZF+TteOHNu2rDr01mJVZzPjNJ/zy4sNg7
L0P0uuqCp3ylh563c3t+slL/9XFoVDNytD46qJlmDDcOYczNjf5An6dyWBJEX348
d0FdWOw5h45lJKhMd1L9WNLymxj3gQ9a3okfhiEqyunsZA4SbMNCPgy4an8tzBsd
HsX1dNgD6P8aoy2umG6SvqgAoPb0mZxlVVT1NdbXN0uybdv/mUJgjDHNsbaCYOxG
UNBfT/p5VQxURhRuNqHsFYvHtA6pxt8mZBbwsHC6b/uOYgPXPrLbM4oQztF2YEzI
RDOr2kmA+JbEj5qKOeQa3BVGT5bUeLRWH+fDFiXq6ubdBdvHAifPJyGdYgAFLvZq
jm85WJJeNvluwB602JUJ/FFxCYe6sKL7jaqfZJClqZrscUDxve0Fckh9xLrQ/il2
0W1VqfxuWeFL6P0SgJOr7aZxbdA293o1/X10E9o6sMuWoCtHfk8=
=jSBA
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Question Regarding McastServiceImpl#setupSocket

2019-05-29 Thread Gurkan Erdogdu
HiIn an McastServiceImpl#setupSocket method, if the user configures the 
mcastBindAddress, it will use the socket to bind to this address. But, in the 
code below, it uses the "address" field while creating the socket. Is this 
correct ?

if (mcastBindAddress != null) {
 try {
    log.info(sm.getString("mcastServiceImpl.bind", address, 
Integer.toString(port)));
    socket = new MulticastSocket(new 
InetSocketAddress(address,port));
    } catch (BindException e) {
Regards.Gurkan