RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Seán Coffey
JDK 10 fix required to correct a race issue in NetworkInterface. I don't
believe the ifreq struct needs to be static in any case. New auto unit
testcase also. I propose to skip this fix for JDK 9 and fix in an update
release for that family. I also plan to port this to jdk8u-dev.

https://bugs.openjdk.java.net/browse/JDK-8182672
webrev : http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/

regards,
Sean.
Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Vyom Tewari
Hi Sean,

with your patch as well your test case is failing on my
laptop(Ubuntu16.04), when i tried to run  on jdk8 i am getting below error.

java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
     at java.net.NetworkInterface.getMacAddr0(Native Method)
     at
java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457)
     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
     at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
     at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
     at java.lang.Thread.run(Thread.java:745)
java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
     at java.net.NetworkInterface.getMacAddr0(Native Method)
     at
java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457)
     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
     at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
     at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
     at java.lang.Thread.run(Thread.java:745)
Exception in thread "main" java.lang.RuntimeException: Failed
     at com.java.test.GetMacAddress.main(GetMacAddress.java:96)
mac id is null for interface cscotun0- Thread0
Testing: cscotun0
mac id is null for interface cscotun0- Thread3
Testing: cscotun0

Thanks,

Vyom


On Thursday 22 June 2017 09:59 PM, Seán Coffey wrote:

> JDK 10 fix required to correct a race issue in NetworkInterface. I
> don't believe the ifreq struct needs to be static in any case. New
> auto unit testcase also. I propose to skip this fix for JDK 9 and fix
> in an update release for that family. I also plan to port this to
> jdk8u-dev.
>
> https://bugs.openjdk.java.net/browse/JDK-8182672
> webrev : http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
>
> regards,
> Sean.

Reply | Threaded
Open this post in threaded view
|

RE: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Langer, Christoph
In reply to this post by Seán Coffey
Hi Sean,

the patch to change the static declaration of struct ifreq ifr into a non static declaration should be done in any case. I had suspected the issue should disappear then but as Vyom told otherwise, I'll also try to test this.

As for the test: NetworkInterface.getNetworkInterfaces() will return a typed enumeration, so you could iterate like:

for (NetworkInterface ni : NetworkInterface.getNetworkInterfaces()) {
   ...
}

Then the code would be more compact.

I'll get back to you with the results of my testing.

Best regards
Christoph

> -----Original Message-----
> From: Seán Coffey [mailto:[hidden email]]
> Sent: Donnerstag, 22. Juni 2017 18:29
> To: OpenJDK Network Dev list <[hidden email]>; Langer,
> Christoph <[hidden email]>
> Subject: RFR : 8182672: Java 8u121 on Linux intermittently returns null for
> MAC address
>
> JDK 10 fix required to correct a race issue in NetworkInterface. I don't
> believe the ifreq struct needs to be static in any case. New auto unit
> testcase also. I propose to skip this fix for JDK 9 and fix in an update
> release for that family. I also plan to port this to jdk8u-dev.
>
> https://bugs.openjdk.java.net/browse/JDK-8182672
> webrev :
> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
>
> regards,
> Sean.
Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Seán Coffey
In reply to this post by Vyom Tewari
Hi Vyom,

thanks for testing. Null is a valid value for some interfaces. I've
excluded the loopback interface from being testing. Perhaps there's
other issues at play here.  We know that getHardwareAddress() can throw
SocketException if I/O fails. For this particular scenario we're not
interested in that and perhaps that can be ignored.

I'll take another look.

regards,
Sean.

On 22/06/2017 18:50, Vyom Tewari wrote:

> Hi Sean,
>
> with your patch as well your test case is failing on my
> laptop(Ubuntu16.04), when i tried to run  on jdk8 i am getting below
> error.
>
> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>     at java.net.NetworkInterface.getMacAddr0(Native Method)
>     at
> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457)
>     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>     at java.lang.Thread.run(Thread.java:745)
> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>     at java.net.NetworkInterface.getMacAddr0(Native Method)
>     at
> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457)
>     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>     at java.lang.Thread.run(Thread.java:745)
> Exception in thread "main" java.lang.RuntimeException: Failed
>     at com.java.test.GetMacAddress.main(GetMacAddress.java:96)
> mac id is null for interface cscotun0- Thread0
> Testing: cscotun0
> mac id is null for interface cscotun0- Thread3
> Testing: cscotun0
>
> Thanks,
>
> Vyom
>
>
> On Thursday 22 June 2017 09:59 PM, Seán Coffey wrote:
>> JDK 10 fix required to correct a race issue in NetworkInterface. I
>> don't believe the ifreq struct needs to be static in any case. New
>> auto unit testcase also. I propose to skip this fix for JDK 9 and fix
>> in an update release for that family. I also plan to port this to
>> jdk8u-dev.
>>
>> https://bugs.openjdk.java.net/browse/JDK-8182672
>> webrev :
>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
>>
>> regards,
>> Sean.
>

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Mark Sheppard
In reply to this post by Seán Coffey
Hi Sean,
  main change looks fine - it sorts the reported problem. 

ran your test against jdk8 152 and a recent jdk9 builds to verify that your test failure occurs.
The failure is seen, together with an additional (intermittent) exception:

java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
at java.base/java.net.NetworkInterface.getMacAddr0(Native Method)
at java.base/java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:504)
at NetworkInterfaceGetMacAddressThreadedTest.run(NetworkInterfaceGetMacAddressThreadedTest.java:59)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1161)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)

The exception looks a bit confusing when mingled with test output. But this
doesn't occur in the fix version.

The exception is most likely a consequence of the non thread safe characteristic of the the current Linux
getMacAddress - what is actually in the ifr variable, when multiple threads are modifying it, when the  ioctl is called?
(who knows, who can tell, is this heaven, is this hell!!)

picked up you fix build and the test passes  fine,  as does the original test case reporting the issue.

also from a consistency perspective, the test is modifying two shared static variable
without synchronization. Maybe these should be volatile, at least?

regards
Mark

On 22/06/2017 17:29, Seán Coffey wrote:
JDK 10 fix required to correct a race issue in NetworkInterface. I don't believe the ifreq struct needs to be static in any case. New auto unit testcase also. I propose to skip this fix for JDK 9 and fix in an update release for that family. I also plan to port this to jdk8u-dev.

https://bugs.openjdk.java.net/browse/JDK-8182672
webrev : http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/

regards,
Sean.

Reply | Threaded
Open this post in threaded view
|

RE: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Langer, Christoph
In reply to this post by Seán Coffey
Hi Sean,

I played with it a bit more and now really understand Vyoms observation. So, what he sees is not the original concurrency issue but he encounters a SocketException on some interface, where this is supposed to occur upon calling getHardwareAddress().

So, to enable the testcase to run robustly on any platform, any hardware and any network configuration, I suggest to modify the test like this:

1. In main, enumerate all interfaces once
2. Iterate over all interfaces, exlude loopback and see if a single call to getHardwareAddress() won't yield null or an Exception.
3. For each interface where a valid mac address could be obtained once, start the executor threads to stress getHardwareAddress() in parallel, e.g. like 5 threads doing it 100 times in parallel. I would also suggest to use per thread counters instead of one global 'count' as we have right now.

Furthermore, the test output could be improved a bit, e.g. when it comes to an exception, the thread name could be mentioned, too.

Best regards
Christoph

> -----Original Message-----
> From: net-dev [mailto:[hidden email]] On Behalf Of
> Seán Coffey
> Sent: Donnerstag, 22. Juni 2017 20:17
> To: Vyom Tewari <[hidden email]>; net-dev <net-
> [hidden email]>
> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for
> MAC address
>
> Hi Vyom,
>
> thanks for testing. Null is a valid value for some interfaces. I've
> excluded the loopback interface from being testing. Perhaps there's
> other issues at play here.  We know that getHardwareAddress() can throw
> SocketException if I/O fails. For this particular scenario we're not
> interested in that and perhaps that can be ignored.
>
> I'll take another look.
>
> regards,
> Sean.
>
> On 22/06/2017 18:50, Vyom Tewari wrote:
> > Hi Sean,
> >
> > with your patch as well your test case is failing on my
> > laptop(Ubuntu16.04), when i tried to run  on jdk8 i am getting below
> > error.
> >
> > java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
> >     at java.net.NetworkInterface.getMacAddr0(Native Method)
> >     at
> >
> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
> )
> >     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
> >     at
> >
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
> a:1142)
> >     at
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
> va:617)
> >     at java.lang.Thread.run(Thread.java:745)
> > java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
> >     at java.net.NetworkInterface.getMacAddr0(Native Method)
> >     at
> >
> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
> )
> >     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
> >     at
> >
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
> a:1142)
> >     at
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
> va:617)
> >     at java.lang.Thread.run(Thread.java:745)
> > Exception in thread "main" java.lang.RuntimeException: Failed
> >     at com.java.test.GetMacAddress.main(GetMacAddress.java:96)
> > mac id is null for interface cscotun0- Thread0
> > Testing: cscotun0
> > mac id is null for interface cscotun0- Thread3
> > Testing: cscotun0
> >
> > Thanks,
> >
> > Vyom
> >
> >
> > On Thursday 22 June 2017 09:59 PM, Seán Coffey wrote:
> >> JDK 10 fix required to correct a race issue in NetworkInterface. I
> >> don't believe the ifreq struct needs to be static in any case. New
> >> auto unit testcase also. I propose to skip this fix for JDK 9 and fix
> >> in an update release for that family. I also plan to port this to
> >> jdk8u-dev.
> >>
> >> https://bugs.openjdk.java.net/browse/JDK-8182672
> >> webrev :
> >> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
> >>
> >> regards,
> >> Sean.
> >

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Vyom Tewari
In reply to this post by Seán Coffey
Hi Sean,

i  debug the failure and it look like you need to modify your test and
make it more robust. As Christoph suggested first call
"getHardwareAddress" and check if is not null then only iterate 100
time. This way your test will run on any platform and one minor comment
make your global variables(count&failed ) volatile.

I did the changes at my local env and it did worked for me  and your
modified test did not failed after fix.

Thanks,

Vyom


On Thursday 22 June 2017 11:46 PM, Seán Coffey wrote:

> Hi Vyom,
>
> thanks for testing. Null is a valid value for some interfaces. I've
> excluded the loopback interface from being testing. Perhaps there's
> other issues at play here.  We know that getHardwareAddress() can
> throw SocketException if I/O fails. For this particular scenario we're
> not interested in that and perhaps that can be ignored.
>
> I'll take another look.
>
> regards,
> Sean.
>
> On 22/06/2017 18:50, Vyom Tewari wrote:
>> Hi Sean,
>>
>> with your patch as well your test case is failing on my
>> laptop(Ubuntu16.04), when i tried to run  on jdk8 i am getting below
>> error.
>>
>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>>     at java.net.NetworkInterface.getMacAddr0(Native Method)
>>     at
>> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457)
>>     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>>     at
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>>     at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>>     at java.lang.Thread.run(Thread.java:745)
>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>>     at java.net.NetworkInterface.getMacAddr0(Native Method)
>>     at
>> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457)
>>     at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>>     at
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>>     at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>>     at java.lang.Thread.run(Thread.java:745)
>> Exception in thread "main" java.lang.RuntimeException: Failed
>>     at com.java.test.GetMacAddress.main(GetMacAddress.java:96)
>> mac id is null for interface cscotun0- Thread0
>> Testing: cscotun0
>> mac id is null for interface cscotun0- Thread3
>> Testing: cscotun0
>>
>> Thanks,
>>
>> Vyom
>>
>>
>> On Thursday 22 June 2017 09:59 PM, Seán Coffey wrote:
>>> JDK 10 fix required to correct a race issue in NetworkInterface. I
>>> don't believe the ifreq struct needs to be static in any case. New
>>> auto unit testcase also. I propose to skip this fix for JDK 9 and
>>> fix in an update release for that family. I also plan to port this
>>> to jdk8u-dev.
>>>
>>> https://bugs.openjdk.java.net/browse/JDK-8182672
>>> webrev :
>>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
>>>
>>> regards,
>>> Sean.
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Seán Coffey
In reply to this post by Langer, Christoph
Thanks to Christoph, Vyom and Mark for the reviews.

I've improved the testcase as per feedback. Hope this meets all requests :

http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/

Regards,
Sean.

On 22/06/17 22:36, Langer, Christoph wrote:

> Hi Sean,
>
> I played with it a bit more and now really understand Vyoms observation. So, what he sees is not the original concurrency issue but he encounters a SocketException on some interface, where this is supposed to occur upon calling getHardwareAddress().
>
> So, to enable the testcase to run robustly on any platform, any hardware and any network configuration, I suggest to modify the test like this:
>
> 1. In main, enumerate all interfaces once
> 2. Iterate over all interfaces, exlude loopback and see if a single call to getHardwareAddress() won't yield null or an Exception.
> 3. For each interface where a valid mac address could be obtained once, start the executor threads to stress getHardwareAddress() in parallel, e.g. like 5 threads doing it 100 times in parallel. I would also suggest to use per thread counters instead of one global 'count' as we have right now.
>
> Furthermore, the test output could be improved a bit, e.g. when it comes to an exception, the thread name could be mentioned, too.
>
> Best regards
> Christoph
>
>> -----Original Message-----
>> From: net-dev [mailto:[hidden email]] On Behalf Of
>> Seán Coffey
>> Sent: Donnerstag, 22. Juni 2017 20:17
>> To: Vyom Tewari <[hidden email]>; net-dev <net-
>> [hidden email]>
>> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for
>> MAC address
>>
>> Hi Vyom,
>>
>> thanks for testing. Null is a valid value for some interfaces. I've
>> excluded the loopback interface from being testing. Perhaps there's
>> other issues at play here.  We know that getHardwareAddress() can throw
>> SocketException if I/O fails. For this particular scenario we're not
>> interested in that and perhaps that can be ignored.
>>
>> I'll take another look.
>>
>> regards,
>> Sean.
>>
>> On 22/06/2017 18:50, Vyom Tewari wrote:
>>> Hi Sean,
>>>
>>> with your patch as well your test case is failing on my
>>> laptop(Ubuntu16.04), when i tried to run  on jdk8 i am getting below
>>> error.
>>>
>>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>>>      at java.net.NetworkInterface.getMacAddr0(Native Method)
>>>      at
>>>
>> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
>> )
>>>      at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>>>      at
>>>
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
>> a:1142)
>>>      at
>>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
>> va:617)
>>>      at java.lang.Thread.run(Thread.java:745)
>>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>>>      at java.net.NetworkInterface.getMacAddr0(Native Method)
>>>      at
>>>
>> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
>> )
>>>      at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>>>      at
>>>
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
>> a:1142)
>>>      at
>>>
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
>> va:617)
>>>      at java.lang.Thread.run(Thread.java:745)
>>> Exception in thread "main" java.lang.RuntimeException: Failed
>>>      at com.java.test.GetMacAddress.main(GetMacAddress.java:96)
>>> mac id is null for interface cscotun0- Thread0
>>> Testing: cscotun0
>>> mac id is null for interface cscotun0- Thread3
>>> Testing: cscotun0
>>>
>>> Thanks,
>>>
>>> Vyom
>>>
>>>
>>> On Thursday 22 June 2017 09:59 PM, Seán Coffey wrote:
>>>> JDK 10 fix required to correct a race issue in NetworkInterface. I
>>>> don't believe the ifreq struct needs to be static in any case. New
>>>> auto unit testcase also. I propose to skip this fix for JDK 9 and fix
>>>> in an update release for that family. I also plan to port this to
>>>> jdk8u-dev.
>>>>
>>>> https://bugs.openjdk.java.net/browse/JDK-8182672
>>>> webrev :
>>>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
>>>>
>>>> regards,
>>>> Sean.

Reply | Threaded
Open this post in threaded view
|

RE: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Langer, Christoph
Hi Seán,

this looks very good.

I've got a few minor points:

1. In line 65 where you catch a possible unexpected exception, you could also mention the thread name in the output.
2. I would check for failure condition at the end of each test loop(line 91, for (NetworkInterface ni : toTest)... ) after a particular interface was tested and in the case of failed==true, terminate the loop. If we see an error with one interface, it's probably not necessary to test others.
3. line 100,101:
            while (!executor.isTerminated()) {
            }
This looks a bit odd. Maybe you should call executor.awaitTermination() inside the loop? Or you could as well use executor.invokeAll() which will return only after all threads are done.
4. line 96:
                        new GetMacAddress(ni, ni.getName() +"-Thread-" + i);
There's a space missing between + and "-Thread-".

Best regards
Christoph



> -----Original Message-----
> From: Seán Coffey [mailto:[hidden email]]
> Sent: Freitag, 23. Juni 2017 11:57
> To: Langer, Christoph <[hidden email]>
> Cc: Vyom Tewari <[hidden email]>; net-dev <net-
> [hidden email]>; Mark Sheppard <[hidden email]>
> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for
> MAC address
>
> Thanks to Christoph, Vyom and Mark for the reviews.
>
> I've improved the testcase as per feedback. Hope this meets all requests :
>
> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/
>
> Regards,
> Sean.
>
> On 22/06/17 22:36, Langer, Christoph wrote:
> > Hi Sean,
> >
> > I played with it a bit more and now really understand Vyoms observation.
> So, what he sees is not the original concurrency issue but he encounters a
> SocketException on some interface, where this is supposed to occur upon
> calling getHardwareAddress().
> >
> > So, to enable the testcase to run robustly on any platform, any hardware
> and any network configuration, I suggest to modify the test like this:
> >
> > 1. In main, enumerate all interfaces once
> > 2. Iterate over all interfaces, exlude loopback and see if a single call to
> getHardwareAddress() won't yield null or an Exception.
> > 3. For each interface where a valid mac address could be obtained once,
> start the executor threads to stress getHardwareAddress() in parallel, e.g.
> like 5 threads doing it 100 times in parallel. I would also suggest to use per
> thread counters instead of one global 'count' as we have right now.
> >
> > Furthermore, the test output could be improved a bit, e.g. when it comes
> to an exception, the thread name could be mentioned, too.
> >
> > Best regards
> > Christoph
> >
> >> -----Original Message-----
> >> From: net-dev [mailto:[hidden email]] On Behalf Of
> >> Seán Coffey
> >> Sent: Donnerstag, 22. Juni 2017 20:17
> >> To: Vyom Tewari <[hidden email]>; net-dev <net-
> >> [hidden email]>
> >> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null
> for
> >> MAC address
> >>
> >> Hi Vyom,
> >>
> >> thanks for testing. Null is a valid value for some interfaces. I've
> >> excluded the loopback interface from being testing. Perhaps there's
> >> other issues at play here.  We know that getHardwareAddress() can
> throw
> >> SocketException if I/O fails. For this particular scenario we're not
> >> interested in that and perhaps that can be ignored.
> >>
> >> I'll take another look.
> >>
> >> regards,
> >> Sean.
> >>
> >> On 22/06/2017 18:50, Vyom Tewari wrote:
> >>> Hi Sean,
> >>>
> >>> with your patch as well your test case is failing on my
> >>> laptop(Ubuntu16.04), when i tried to run  on jdk8 i am getting below
> >>> error.
> >>>
> >>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR)
> failed)
> >>>      at java.net.NetworkInterface.getMacAddr0(Native Method)
> >>>      at
> >>>
> >>
> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
> >> )
> >>>      at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
> >>>      at
> >>>
> >>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
> >> a:1142)
> >>>      at
> >>>
> >>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
> >> va:617)
> >>>      at java.lang.Thread.run(Thread.java:745)
> >>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR)
> failed)
> >>>      at java.net.NetworkInterface.getMacAddr0(Native Method)
> >>>      at
> >>>
> >>
> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
> >> )
> >>>      at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
> >>>      at
> >>>
> >>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
> >> a:1142)
> >>>      at
> >>>
> >>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
> >> va:617)
> >>>      at java.lang.Thread.run(Thread.java:745)
> >>> Exception in thread "main" java.lang.RuntimeException: Failed
> >>>      at com.java.test.GetMacAddress.main(GetMacAddress.java:96)
> >>> mac id is null for interface cscotun0- Thread0
> >>> Testing: cscotun0
> >>> mac id is null for interface cscotun0- Thread3
> >>> Testing: cscotun0
> >>>
> >>> Thanks,
> >>>
> >>> Vyom
> >>>
> >>>
> >>> On Thursday 22 June 2017 09:59 PM, Seán Coffey wrote:
> >>>> JDK 10 fix required to correct a race issue in NetworkInterface. I
> >>>> don't believe the ifreq struct needs to be static in any case. New
> >>>> auto unit testcase also. I propose to skip this fix for JDK 9 and fix
> >>>> in an update release for that family. I also plan to port this to
> >>>> jdk8u-dev.
> >>>>
> >>>> https://bugs.openjdk.java.net/browse/JDK-8182672
> >>>> webrev :
> >>>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
> >>>>
> >>>> regards,
> >>>> Sean.

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Vyom Tewari
In reply to this post by Seán Coffey
Hi Sean,

latest test code looks good, one minor bit, in MT program
"ex.printStackTrace();" will not help as output will be screwed. I will
suggested to pass the original exception to line 106.

throw new RuntimeException(originalException);

Thanks,

Vyom


On Friday 23 June 2017 03:26 PM, Seán Coffey wrote:

> Thanks to Christoph, Vyom and Mark for the reviews.
>
> I've improved the testcase as per feedback. Hope this meets all
> requests :
>
> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/
>
> Regards,
> Sean.
>
> On 22/06/17 22:36, Langer, Christoph wrote:
>> Hi Sean,
>>
>> I played with it a bit more and now really understand Vyoms
>> observation. So, what he sees is not the original concurrency issue
>> but he encounters a SocketException on some interface, where this is
>> supposed to occur upon calling getHardwareAddress().
>>
>> So, to enable the testcase to run robustly on any platform, any
>> hardware and any network configuration, I suggest to modify the test
>> like this:
>>
>> 1. In main, enumerate all interfaces once
>> 2. Iterate over all interfaces, exlude loopback and see if a single
>> call to getHardwareAddress() won't yield null or an Exception.
>> 3. For each interface where a valid mac address could be obtained
>> once, start the executor threads to stress getHardwareAddress() in
>> parallel, e.g. like 5 threads doing it 100 times in parallel. I would
>> also suggest to use per thread counters instead of one global 'count'
>> as we have right now.
>>
>> Furthermore, the test output could be improved a bit, e.g. when it
>> comes to an exception, the thread name could be mentioned, too.
>>
>> Best regards
>> Christoph
>>
>>> -----Original Message-----
>>> From: net-dev [mailto:[hidden email]] On Behalf Of
>>> Seán Coffey
>>> Sent: Donnerstag, 22. Juni 2017 20:17
>>> To: Vyom Tewari <[hidden email]>; net-dev <net-
>>> [hidden email]>
>>> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently
>>> returns null for
>>> MAC address
>>>
>>> Hi Vyom,
>>>
>>> thanks for testing. Null is a valid value for some interfaces. I've
>>> excluded the loopback interface from being testing. Perhaps there's
>>> other issues at play here.  We know that getHardwareAddress() can throw
>>> SocketException if I/O fails. For this particular scenario we're not
>>> interested in that and perhaps that can be ignored.
>>>
>>> I'll take another look.
>>>
>>> regards,
>>> Sean.
>>>
>>> On 22/06/2017 18:50, Vyom Tewari wrote:
>>>> Hi Sean,
>>>>
>>>> with your patch as well your test case is failing on my
>>>> laptop(Ubuntu16.04), when i tried to run  on jdk8 i am getting below
>>>> error.
>>>>
>>>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>>>>      at java.net.NetworkInterface.getMacAddr0(Native Method)
>>>>      at
>>>>
>>> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
>>> )
>>>>      at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>>>>      at
>>>>
>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
>>>
>>> a:1142)
>>>>      at
>>>>
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
>>>
>>> va:617)
>>>>      at java.lang.Thread.run(Thread.java:745)
>>>> java.net.SocketException: No such device (ioctl(SIOCGIFHWADDR) failed)
>>>>      at java.net.NetworkInterface.getMacAddr0(Native Method)
>>>>      at
>>>>
>>> java.net.NetworkInterface.getHardwareAddress(NetworkInterface.java:457
>>> )
>>>>      at com.java.test.GetMacAddress.run(GetMacAddress.java:66)
>>>>      at
>>>>
>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
>>>
>>> a:1142)
>>>>      at
>>>>
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
>>>
>>> va:617)
>>>>      at java.lang.Thread.run(Thread.java:745)
>>>> Exception in thread "main" java.lang.RuntimeException: Failed
>>>>      at com.java.test.GetMacAddress.main(GetMacAddress.java:96)
>>>> mac id is null for interface cscotun0- Thread0
>>>> Testing: cscotun0
>>>> mac id is null for interface cscotun0- Thread3
>>>> Testing: cscotun0
>>>>
>>>> Thanks,
>>>>
>>>> Vyom
>>>>
>>>>
>>>> On Thursday 22 June 2017 09:59 PM, Seán Coffey wrote:
>>>>> JDK 10 fix required to correct a race issue in NetworkInterface. I
>>>>> don't believe the ifreq struct needs to be static in any case. New
>>>>> auto unit testcase also. I propose to skip this fix for JDK 9 and fix
>>>>> in an update release for that family. I also plan to port this to
>>>>> jdk8u-dev.
>>>>>
>>>>> https://bugs.openjdk.java.net/browse/JDK-8182672
>>>>> webrev :
>>>>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10/webrev/
>>>>>
>>>>> regards,
>>>>> Sean.
>

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Chris Hegarty
In reply to this post by Seán Coffey


On 23/06/17 10:56, Seán Coffey wrote:
> Thanks to Christoph, Vyom and Mark for the reviews.
>
> I've improved the testcase as per feedback. Hope this meets all requests :
>
> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/

The change looks good.

Sean and I did a live coding session and arrived at the following
version of the test.

-Chris.

/*
  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License
version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */

/*
  * @test
  * @bug 8182672
  * @summary Java 8u121 on Linux intermittently returns null for MAC address
  */

import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.Phaser;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class GetMacAddress implements Callable<Exception> {
     static final int NUM_THREADS = 5;
     static final int NUM_ITERS = 100;
     static volatile boolean failed; // false

     final String threadName;
     final NetworkInterface ni;
     final Phaser startingGate;

     public GetMacAddress(NetworkInterface ni, String name, Phaser phaser) {
         this.ni = ni;
         this.threadName = name;
         this.startingGate = phaser;
     }

     @Override
     public Exception call() {
         int count = 0;
         startingGate.arriveAndAwaitAdvance();
         try {
             for (int i = 0; i < NUM_ITERS; i++) {
                 ni.getMTU();
                 byte[] addr = ni.getHardwareAddress();
                 if (addr == null) {
                     System.out.println(threadName + ". mac id is null");
                     failed = true;
                 }
                 count = count + 1;
                 if (count % 100 == 0) {
                     System.out.println(threadName + ". count is " + count);
                 }
             }
         } catch (Exception ex) {
             System.out.println(threadName + ". Not expecting
exception:" + ex.getMessage());
             failed = true;
             return ex;
         }
         return null;
     }

     static final Predicate<NetworkInterface> hasHardwareAddress = ni -> {
         try {
             if (ni.getHardwareAddress() == null) {
                 System.out.println("Not testing null addr: " +
ni.getName());
                 return false;
             }
         } catch (Exception ex) {
             System.out.println("Not testing: " + ni.getName() +
                     " " + ex.getMessage());
         }
         return true;
     };

     public static void main(String[] args) throws Exception {
         List<NetworkInterface> toTest =
NetworkInterface.networkInterfaces()
                         .filter(hasHardwareAddress)
                         .collect(Collectors.toList());

         ExecutorService executor =
Executors.newFixedThreadPool(NUM_THREADS);

         for (NetworkInterface ni : toTest) {
             Phaser startingGate = new Phaser(NUM_THREADS);
             System.out.println("Testing: " + ni.getName());
             List<Callable<Exception>> list = new ArrayList<>();
             for (int i = 0; i < NUM_THREADS; i++)
                 list.add(new GetMacAddress(ni, ni.getName() +
"-Thread-" + i, startingGate));
             List<Future<Exception>> futures = executor.invokeAll(list);
             for (Future<Exception> f : futures) {
                 if (f.get() != null)
                     f.get().printStackTrace(System.out);
             }
             if (failed)
                 break;
         }
         executor.shutdownNow();
         if (!failed) {
             System.out.println("PASSED - Finished all threads");
         } else {
             throw new RuntimeException("Failed");
         }
     }
}
Reply | Threaded
Open this post in threaded view
|

RE: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Langer, Christoph
Hi,

looks like a great piece of modern concurrent Java coding :) Well done! +1

Best regards
Christoph

> -----Original Message-----
> From: Chris Hegarty [mailto:[hidden email]]
> Sent: Freitag, 23. Juni 2017 15:28
> To: Seán Coffey <[hidden email]>; Langer, Christoph
> <[hidden email]>
> Cc: net-dev <[hidden email]>
> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for
> MAC address
>
>
>
> On 23/06/17 10:56, Seán Coffey wrote:
> > Thanks to Christoph, Vyom and Mark for the reviews.
> >
> > I've improved the testcase as per feedback. Hope this meets all requests :
> >
> > http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/
>
> The change looks good.
>
> Sean and I did a live coding session and arrived at the following
> version of the test.
>
> -Chris.
>
> /*
>   * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
>   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>   *
>   * This code is free software; you can redistribute it and/or modify it
>   * under the terms of the GNU General Public License version 2 only, as
>   * published by the Free Software Foundation.
>   *
>   * This code is distributed in the hope that it will be useful, but WITHOUT
>   * ANY WARRANTY; without even the implied warranty of
> MERCHANTABILITY or
>   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
> License
>   * version 2 for more details (a copy is included in the LICENSE file that
>   * accompanied this code).
>   *
>   * You should have received a copy of the GNU General Public License
> version
>   * 2 along with this work; if not, write to the Free Software Foundation,
>   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
>   *
>   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065
> USA
>   * or visit www.oracle.com if you need additional information or have any
>   * questions.
>   */
>
> /*
>   * @test
>   * @bug 8182672
>   * @summary Java 8u121 on Linux intermittently returns null for MAC
> address
>   */
>
> import java.net.NetworkInterface;
> import java.util.ArrayList;
> import java.util.List;
> import java.util.concurrent.Callable;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
> import java.util.concurrent.Future;
> import java.util.concurrent.Phaser;
> import java.util.function.Predicate;
> import java.util.stream.Collectors;
>
> public class GetMacAddress implements Callable<Exception> {
>      static final int NUM_THREADS = 5;
>      static final int NUM_ITERS = 100;
>      static volatile boolean failed; // false
>
>      final String threadName;
>      final NetworkInterface ni;
>      final Phaser startingGate;
>
>      public GetMacAddress(NetworkInterface ni, String name, Phaser phaser) {
>          this.ni = ni;
>          this.threadName = name;
>          this.startingGate = phaser;
>      }
>
>      @Override
>      public Exception call() {
>          int count = 0;
>          startingGate.arriveAndAwaitAdvance();
>          try {
>              for (int i = 0; i < NUM_ITERS; i++) {
>                  ni.getMTU();
>                  byte[] addr = ni.getHardwareAddress();
>                  if (addr == null) {
>                      System.out.println(threadName + ". mac id is null");
>                      failed = true;
>                  }
>                  count = count + 1;
>                  if (count % 100 == 0) {
>                      System.out.println(threadName + ". count is " + count);
>                  }
>              }
>          } catch (Exception ex) {
>              System.out.println(threadName + ". Not expecting
> exception:" + ex.getMessage());
>              failed = true;
>              return ex;
>          }
>          return null;
>      }
>
>      static final Predicate<NetworkInterface> hasHardwareAddress = ni -> {
>          try {
>              if (ni.getHardwareAddress() == null) {
>                  System.out.println("Not testing null addr: " +
> ni.getName());
>                  return false;
>              }
>          } catch (Exception ex) {
>              System.out.println("Not testing: " + ni.getName() +
>                      " " + ex.getMessage());
>          }
>          return true;
>      };
>
>      public static void main(String[] args) throws Exception {
>          List<NetworkInterface> toTest =
> NetworkInterface.networkInterfaces()
>                          .filter(hasHardwareAddress)
>                          .collect(Collectors.toList());
>
>          ExecutorService executor =
> Executors.newFixedThreadPool(NUM_THREADS);
>
>          for (NetworkInterface ni : toTest) {
>              Phaser startingGate = new Phaser(NUM_THREADS);
>              System.out.println("Testing: " + ni.getName());
>              List<Callable<Exception>> list = new ArrayList<>();
>              for (int i = 0; i < NUM_THREADS; i++)
>                  list.add(new GetMacAddress(ni, ni.getName() +
> "-Thread-" + i, startingGate));
>              List<Future<Exception>> futures = executor.invokeAll(list);
>              for (Future<Exception> f : futures) {
>                  if (f.get() != null)
>                      f.get().printStackTrace(System.out);
>              }
>              if (failed)
>                  break;
>          }
>          executor.shutdownNow();
>          if (!failed) {
>              System.out.println("PASSED - Finished all threads");
>          } else {
>              throw new RuntimeException("Failed");
>          }
>      }
> }
Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Seán Coffey
Thanks all. There were a few shouts from Chris in the office when he saw
my Enumeration code ;)

I'm running this through our test system again and will push if I get
green results.

Regards,
Sean.

On 23/06/17 14:40, Langer, Christoph wrote:

> Hi,
>
> looks like a great piece of modern concurrent Java coding :) Well done! +1
>
> Best regards
> Christoph
>
>> -----Original Message-----
>> From: Chris Hegarty [mailto:[hidden email]]
>> Sent: Freitag, 23. Juni 2017 15:28
>> To: Seán Coffey <[hidden email]>; Langer, Christoph
>> <[hidden email]>
>> Cc: net-dev <[hidden email]>
>> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for
>> MAC address
>>
>>
>>
>> On 23/06/17 10:56, Seán Coffey wrote:
>>> Thanks to Christoph, Vyom and Mark for the reviews.
>>>
>>> I've improved the testcase as per feedback. Hope this meets all requests :
>>>
>>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/
>> The change looks good.
>>
>> Sean and I did a live coding session and arrived at the following
>> version of the test.
>>
>> -Chris.
>>
>> /*
>>    * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
>>    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>>    *
>>    * This code is free software; you can redistribute it and/or modify it
>>    * under the terms of the GNU General Public License version 2 only, as
>>    * published by the Free Software Foundation.
>>    *
>>    * This code is distributed in the hope that it will be useful, but WITHOUT
>>    * ANY WARRANTY; without even the implied warranty of
>> MERCHANTABILITY or
>>    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>> License
>>    * version 2 for more details (a copy is included in the LICENSE file that
>>    * accompanied this code).
>>    *
>>    * You should have received a copy of the GNU General Public License
>> version
>>    * 2 along with this work; if not, write to the Free Software Foundation,
>>    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
>>    *
>>    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065
>> USA
>>    * or visit www.oracle.com if you need additional information or have any
>>    * questions.
>>    */
>>
>> /*
>>    * @test
>>    * @bug 8182672
>>    * @summary Java 8u121 on Linux intermittently returns null for MAC
>> address
>>    */
>>
>> import java.net.NetworkInterface;
>> import java.util.ArrayList;
>> import java.util.List;
>> import java.util.concurrent.Callable;
>> import java.util.concurrent.ExecutorService;
>> import java.util.concurrent.Executors;
>> import java.util.concurrent.Future;
>> import java.util.concurrent.Phaser;
>> import java.util.function.Predicate;
>> import java.util.stream.Collectors;
>>
>> public class GetMacAddress implements Callable<Exception> {
>>       static final int NUM_THREADS = 5;
>>       static final int NUM_ITERS = 100;
>>       static volatile boolean failed; // false
>>
>>       final String threadName;
>>       final NetworkInterface ni;
>>       final Phaser startingGate;
>>
>>       public GetMacAddress(NetworkInterface ni, String name, Phaser phaser) {
>>           this.ni = ni;
>>           this.threadName = name;
>>           this.startingGate = phaser;
>>       }
>>
>>       @Override
>>       public Exception call() {
>>           int count = 0;
>>           startingGate.arriveAndAwaitAdvance();
>>           try {
>>               for (int i = 0; i < NUM_ITERS; i++) {
>>                   ni.getMTU();
>>                   byte[] addr = ni.getHardwareAddress();
>>                   if (addr == null) {
>>                       System.out.println(threadName + ". mac id is null");
>>                       failed = true;
>>                   }
>>                   count = count + 1;
>>                   if (count % 100 == 0) {
>>                       System.out.println(threadName + ". count is " + count);
>>                   }
>>               }
>>           } catch (Exception ex) {
>>               System.out.println(threadName + ". Not expecting
>> exception:" + ex.getMessage());
>>               failed = true;
>>               return ex;
>>           }
>>           return null;
>>       }
>>
>>       static final Predicate<NetworkInterface> hasHardwareAddress = ni -> {
>>           try {
>>               if (ni.getHardwareAddress() == null) {
>>                   System.out.println("Not testing null addr: " +
>> ni.getName());
>>                   return false;
>>               }
>>           } catch (Exception ex) {
>>               System.out.println("Not testing: " + ni.getName() +
>>                       " " + ex.getMessage());
>>           }
>>           return true;
>>       };
>>
>>       public static void main(String[] args) throws Exception {
>>           List<NetworkInterface> toTest =
>> NetworkInterface.networkInterfaces()
>>                           .filter(hasHardwareAddress)
>>                           .collect(Collectors.toList());
>>
>>           ExecutorService executor =
>> Executors.newFixedThreadPool(NUM_THREADS);
>>
>>           for (NetworkInterface ni : toTest) {
>>               Phaser startingGate = new Phaser(NUM_THREADS);
>>               System.out.println("Testing: " + ni.getName());
>>               List<Callable<Exception>> list = new ArrayList<>();
>>               for (int i = 0; i < NUM_THREADS; i++)
>>                   list.add(new GetMacAddress(ni, ni.getName() +
>> "-Thread-" + i, startingGate));
>>               List<Future<Exception>> futures = executor.invokeAll(list);
>>               for (Future<Exception> f : futures) {
>>                   if (f.get() != null)
>>                       f.get().printStackTrace(System.out);
>>               }
>>               if (failed)
>>                   break;
>>           }
>>           executor.shutdownNow();
>>           if (!failed) {
>>               System.out.println("PASSED - Finished all threads");
>>           } else {
>>               throw new RuntimeException("Failed");
>>           }
>>       }
>> }

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Vyom Tewari
In reply to this post by Chris Hegarty
Hi Chris,

test looks good, one minor comment can be ignored, in failing case it
print stack and "Exception in thread "main" java.lang.RuntimeException:
Failed" both. I can see main is declared to throw Exception. Is is
possible to throw exception instead of  printing trace or pass this
exception to last line ?

Thanks,

Vyom


On Friday 23 June 2017 06:58 PM, Chris Hegarty wrote:

>
>
> On 23/06/17 10:56, Seán Coffey wrote:
>> Thanks to Christoph, Vyom and Mark for the reviews.
>>
>> I've improved the testcase as per feedback. Hope this meets all
>> requests :
>>
>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/
>
> The change looks good.
>
> Sean and I did a live coding session and arrived at the following
> version of the test.
>
> -Chris.
>
> /*
>  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
>  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>  *
>  * This code is free software; you can redistribute it and/or modify it
>  * under the terms of the GNU General Public License version 2 only, as
>  * published by the Free Software Foundation.
>  *
>  * This code is distributed in the hope that it will be useful, but
> WITHOUT
>  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>  * version 2 for more details (a copy is included in the LICENSE file
> that
>  * accompanied this code).
>  *
>  * You should have received a copy of the GNU General Public License
> version
>  * 2 along with this work; if not, write to the Free Software Foundation,
>  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
>  *
>  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065
> USA
>  * or visit www.oracle.com if you need additional information or have any
>  * questions.
>  */
>
> /*
>  * @test
>  * @bug 8182672
>  * @summary Java 8u121 on Linux intermittently returns null for MAC
> address
>  */
>
> import java.net.NetworkInterface;
> import java.util.ArrayList;
> import java.util.List;
> import java.util.concurrent.Callable;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
> import java.util.concurrent.Future;
> import java.util.concurrent.Phaser;
> import java.util.function.Predicate;
> import java.util.stream.Collectors;
>
> public class GetMacAddress implements Callable<Exception> {
>     static final int NUM_THREADS = 5;
>     static final int NUM_ITERS = 100;
>     static volatile boolean failed; // false
>
>     final String threadName;
>     final NetworkInterface ni;
>     final Phaser startingGate;
>
>     public GetMacAddress(NetworkInterface ni, String name, Phaser
> phaser) {
>         this.ni = ni;
>         this.threadName = name;
>         this.startingGate = phaser;
>     }
>
>     @Override
>     public Exception call() {
>         int count = 0;
>         startingGate.arriveAndAwaitAdvance();
>         try {
>             for (int i = 0; i < NUM_ITERS; i++) {
>                 ni.getMTU();
>                 byte[] addr = ni.getHardwareAddress();
>                 if (addr == null) {
>                     System.out.println(threadName + ". mac id is null");
>                     failed = true;
>                 }
>                 count = count + 1;
>                 if (count % 100 == 0) {
>                     System.out.println(threadName + ". count is " +
> count);
>                 }
>             }
>         } catch (Exception ex) {
>             System.out.println(threadName + ". Not expecting
> exception:" + ex.getMessage());
>             failed = true;
>             return ex;
>         }
>         return null;
>     }
>
>     static final Predicate<NetworkInterface> hasHardwareAddress = ni -> {
>         try {
>             if (ni.getHardwareAddress() == null) {
>                 System.out.println("Not testing null addr: " +
> ni.getName());
>                 return false;
>             }
>         } catch (Exception ex) {
>             System.out.println("Not testing: " + ni.getName() +
>                     " " + ex.getMessage());
>         }
>         return true;
>     };
>
>     public static void main(String[] args) throws Exception {
>         List<NetworkInterface> toTest =
> NetworkInterface.networkInterfaces()
>                         .filter(hasHardwareAddress)
>                         .collect(Collectors.toList());
>
>         ExecutorService executor =
> Executors.newFixedThreadPool(NUM_THREADS);
>
>         for (NetworkInterface ni : toTest) {
>             Phaser startingGate = new Phaser(NUM_THREADS);
>             System.out.println("Testing: " + ni.getName());
>             List<Callable<Exception>> list = new ArrayList<>();
>             for (int i = 0; i < NUM_THREADS; i++)
>                 list.add(new GetMacAddress(ni, ni.getName() +
> "-Thread-" + i, startingGate));
>             List<Future<Exception>> futures = executor.invokeAll(list);
>             for (Future<Exception> f : futures) {
>                 if (f.get() != null)
>                     f.get().printStackTrace(System.out);
>             }
>             if (failed)
>                 break;
>         }
>         executor.shutdownNow();
>         if (!failed) {
>             System.out.println("PASSED - Finished all threads");
>         } else {
>             throw new RuntimeException("Failed");
>         }
>     }
> }

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Mark Sheppard
In reply to this post by Seán Coffey
a minor observation:
perhaps a slight modification to the test to allow adaptation to jdk8  
(the genesis of the reported problem)
replacing the NetworkInterface.networkInterfaces() with static method
which encapsulates the Stream<NetworkInterface>
creation

     public static Stream<NetworkInterface>
getNetworkInterfacesAsStream() throws Exception {
         //return NetworkInterface.networkInterfaces();

         return
Collections.list(NetworkInterface.getNetworkInterfaces()).stream();
     }


     public static void main(String[] args) throws Exception {
         //List<NetworkInterface> toTest =
NetworkInterface.networkInterfaces()
         List<NetworkInterface> toTest = getNetworkInterfacesAsStream()
                         .filter(hasHardwareAddress)
                         .collect(Collectors.toList());

nonetheless execution of the upgraded test produces neat  compact
diagnostic output with
the exceptions displayed neatly - looks good

regards
Mark

On 23/06/2017 14:47, Seán Coffey wrote:

> Thanks all. There were a few shouts from Chris in the office when he
> saw my Enumeration code ;)
>
> I'm running this through our test system again and will push if I get
> green results.
>
> Regards,
> Sean.
>
> On 23/06/17 14:40, Langer, Christoph wrote:
>> Hi,
>>
>> looks like a great piece of modern concurrent Java coding :) Well
>> done! +1
>>
>> Best regards
>> Christoph
>>
>>> -----Original Message-----
>>> From: Chris Hegarty [mailto:[hidden email]]
>>> Sent: Freitag, 23. Juni 2017 15:28
>>> To: Seán Coffey <[hidden email]>; Langer, Christoph
>>> <[hidden email]>
>>> Cc: net-dev <[hidden email]>
>>> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently
>>> returns null for
>>> MAC address
>>>
>>>
>>>
>>> On 23/06/17 10:56, Seán Coffey wrote:
>>>> Thanks to Christoph, Vyom and Mark for the reviews.
>>>>
>>>> I've improved the testcase as per feedback. Hope this meets all
>>>> requests :
>>>>
>>>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/
>>> The change looks good.
>>>
>>> Sean and I did a live coding session and arrived at the following
>>> version of the test.
>>>
>>> -Chris.
>>>
>>> /*
>>>    * Copyright (c) 2017, Oracle and/or its affiliates. All rights
>>> reserved.
>>>    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>>>    *
>>>    * This code is free software; you can redistribute it and/or
>>> modify it
>>>    * under the terms of the GNU General Public License version 2
>>> only, as
>>>    * published by the Free Software Foundation.
>>>    *
>>>    * This code is distributed in the hope that it will be useful,
>>> but WITHOUT
>>>    * ANY WARRANTY; without even the implied warranty of
>>> MERCHANTABILITY or
>>>    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>>> License
>>>    * version 2 for more details (a copy is included in the LICENSE
>>> file that
>>>    * accompanied this code).
>>>    *
>>>    * You should have received a copy of the GNU General Public License
>>> version
>>>    * 2 along with this work; if not, write to the Free Software
>>> Foundation,
>>>    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
>>>    *
>>>    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA
>>> 94065
>>> USA
>>>    * or visit www.oracle.com if you need additional information or
>>> have any
>>>    * questions.
>>>    */
>>>
>>> /*
>>>    * @test
>>>    * @bug 8182672
>>>    * @summary Java 8u121 on Linux intermittently returns null for MAC
>>> address
>>>    */
>>>
>>> import java.net.NetworkInterface;
>>> import java.util.ArrayList;
>>> import java.util.List;
>>> import java.util.concurrent.Callable;
>>> import java.util.concurrent.ExecutorService;
>>> import java.util.concurrent.Executors;
>>> import java.util.concurrent.Future;
>>> import java.util.concurrent.Phaser;
>>> import java.util.function.Predicate;
>>> import java.util.stream.Collectors;
>>>
>>> public class GetMacAddress implements Callable<Exception> {
>>>       static final int NUM_THREADS = 5;
>>>       static final int NUM_ITERS = 100;
>>>       static volatile boolean failed; // false
>>>
>>>       final String threadName;
>>>       final NetworkInterface ni;
>>>       final Phaser startingGate;
>>>
>>>       public GetMacAddress(NetworkInterface ni, String name, Phaser
>>> phaser) {
>>>           this.ni = ni;
>>>           this.threadName = name;
>>>           this.startingGate = phaser;
>>>       }
>>>
>>>       @Override
>>>       public Exception call() {
>>>           int count = 0;
>>>           startingGate.arriveAndAwaitAdvance();
>>>           try {
>>>               for (int i = 0; i < NUM_ITERS; i++) {
>>>                   ni.getMTU();
>>>                   byte[] addr = ni.getHardwareAddress();
>>>                   if (addr == null) {
>>>                       System.out.println(threadName + ". mac id is
>>> null");
>>>                       failed = true;
>>>                   }
>>>                   count = count + 1;
>>>                   if (count % 100 == 0) {
>>>                       System.out.println(threadName + ". count is "
>>> + count);
>>>                   }
>>>               }
>>>           } catch (Exception ex) {
>>>               System.out.println(threadName + ". Not expecting
>>> exception:" + ex.getMessage());
>>>               failed = true;
>>>               return ex;
>>>           }
>>>           return null;
>>>       }
>>>
>>>       static final Predicate<NetworkInterface> hasHardwareAddress =
>>> ni -> {
>>>           try {
>>>               if (ni.getHardwareAddress() == null) {
>>>                   System.out.println("Not testing null addr: " +
>>> ni.getName());
>>>                   return false;
>>>               }
>>>           } catch (Exception ex) {
>>>               System.out.println("Not testing: " + ni.getName() +
>>>                       " " + ex.getMessage());
>>>           }
>>>           return true;
>>>       };
>>>
>>>       public static void main(String[] args) throws Exception {
>>>           List<NetworkInterface> toTest =
>>> NetworkInterface.networkInterfaces()
>>>                           .filter(hasHardwareAddress)
>>>                           .collect(Collectors.toList());
>>>
>>>           ExecutorService executor =
>>> Executors.newFixedThreadPool(NUM_THREADS);
>>>
>>>           for (NetworkInterface ni : toTest) {
>>>               Phaser startingGate = new Phaser(NUM_THREADS);
>>>               System.out.println("Testing: " + ni.getName());
>>>               List<Callable<Exception>> list = new ArrayList<>();
>>>               for (int i = 0; i < NUM_THREADS; i++)
>>>                   list.add(new GetMacAddress(ni, ni.getName() +
>>> "-Thread-" + i, startingGate));
>>>               List<Future<Exception>> futures =
>>> executor.invokeAll(list);
>>>               for (Future<Exception> f : futures) {
>>>                   if (f.get() != null)
>>>                       f.get().printStackTrace(System.out);
>>>               }
>>>               if (failed)
>>>                   break;
>>>           }
>>>           executor.shutdownNow();
>>>           if (!failed) {
>>>               System.out.println("PASSED - Finished all threads");
>>>           } else {
>>>               throw new RuntimeException("Failed");
>>>           }
>>>       }
>>> }
>

Reply | Threaded
Open this post in threaded view
|

Re: RFR : 8182672: Java 8u121 on Linux intermittently returns null for MAC address

Seán Coffey
Nice suggestion Mark - I've taken that on board with latest webrev.

http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v3/webrev/

There was an issue with the hasHardwareAddress method also. A 'return
false' was missing in the exception block.

Vyom - I discussed your suggestion with Chris - I think it's ok to have
an exception trace printed per interface when an issue occurs. We'll
leave that as is for now.

Final test version being run through test system now. Will push once
finished.

Regards,
Sean.

On 23/06/17 15:36, Mark Sheppard wrote:

> a minor observation:
> perhaps a slight modification to the test to allow adaptation to jdk8  
> (the genesis of the reported problem)
> replacing the NetworkInterface.networkInterfaces() with static method
> which encapsulates the Stream<NetworkInterface>
> creation
>
>     public static Stream<NetworkInterface>
> getNetworkInterfacesAsStream() throws Exception {
>         //return NetworkInterface.networkInterfaces();
>
>         return
> Collections.list(NetworkInterface.getNetworkInterfaces()).stream();
>     }
>
>
>     public static void main(String[] args) throws Exception {
>         //List<NetworkInterface> toTest =
> NetworkInterface.networkInterfaces()
>         List<NetworkInterface> toTest = getNetworkInterfacesAsStream()
>                         .filter(hasHardwareAddress)
>                         .collect(Collectors.toList());
>
> nonetheless execution of the upgraded test produces neat  compact
> diagnostic output with
> the exceptions displayed neatly - looks good
>
> regards
> Mark
>
> On 23/06/2017 14:47, Seán Coffey wrote:
>> Thanks all. There were a few shouts from Chris in the office when he
>> saw my Enumeration code ;)
>>
>> I'm running this through our test system again and will push if I get
>> green results.
>>
>> Regards,
>> Sean.
>>
>> On 23/06/17 14:40, Langer, Christoph wrote:
>>> Hi,
>>>
>>> looks like a great piece of modern concurrent Java coding :) Well
>>> done! +1
>>>
>>> Best regards
>>> Christoph
>>>
>>>> -----Original Message-----
>>>> From: Chris Hegarty [mailto:[hidden email]]
>>>> Sent: Freitag, 23. Juni 2017 15:28
>>>> To: Seán Coffey <[hidden email]>; Langer, Christoph
>>>> <[hidden email]>
>>>> Cc: net-dev <[hidden email]>
>>>> Subject: Re: RFR : 8182672: Java 8u121 on Linux intermittently
>>>> returns null for
>>>> MAC address
>>>>
>>>>
>>>>
>>>> On 23/06/17 10:56, Seán Coffey wrote:
>>>>> Thanks to Christoph, Vyom and Mark for the reviews.
>>>>>
>>>>> I've improved the testcase as per feedback. Hope this meets all
>>>>> requests :
>>>>>
>>>>> http://cr.openjdk.java.net/~coffeys/webrev.8182672.jdk10.v2/webrev/
>>>> The change looks good.
>>>>
>>>> Sean and I did a live coding session and arrived at the following
>>>> version of the test.
>>>>
>>>> -Chris.
>>>>
>>>> /*
>>>>    * Copyright (c) 2017, Oracle and/or its affiliates. All rights
>>>> reserved.
>>>>    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>>>>    *
>>>>    * This code is free software; you can redistribute it and/or
>>>> modify it
>>>>    * under the terms of the GNU General Public License version 2
>>>> only, as
>>>>    * published by the Free Software Foundation.
>>>>    *
>>>>    * This code is distributed in the hope that it will be useful,
>>>> but WITHOUT
>>>>    * ANY WARRANTY; without even the implied warranty of
>>>> MERCHANTABILITY or
>>>>    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>>>> License
>>>>    * version 2 for more details (a copy is included in the LICENSE
>>>> file that
>>>>    * accompanied this code).
>>>>    *
>>>>    * You should have received a copy of the GNU General Public License
>>>> version
>>>>    * 2 along with this work; if not, write to the Free Software
>>>> Foundation,
>>>>    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
>>>>    *
>>>>    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA
>>>> 94065
>>>> USA
>>>>    * or visit www.oracle.com if you need additional information or
>>>> have any
>>>>    * questions.
>>>>    */
>>>>
>>>> /*
>>>>    * @test
>>>>    * @bug 8182672
>>>>    * @summary Java 8u121 on Linux intermittently returns null for MAC
>>>> address
>>>>    */
>>>>
>>>> import java.net.NetworkInterface;
>>>> import java.util.ArrayList;
>>>> import java.util.List;
>>>> import java.util.concurrent.Callable;
>>>> import java.util.concurrent.ExecutorService;
>>>> import java.util.concurrent.Executors;
>>>> import java.util.concurrent.Future;
>>>> import java.util.concurrent.Phaser;
>>>> import java.util.function.Predicate;
>>>> import java.util.stream.Collectors;
>>>>
>>>> public class GetMacAddress implements Callable<Exception> {
>>>>       static final int NUM_THREADS = 5;
>>>>       static final int NUM_ITERS = 100;
>>>>       static volatile boolean failed; // false
>>>>
>>>>       final String threadName;
>>>>       final NetworkInterface ni;
>>>>       final Phaser startingGate;
>>>>
>>>>       public GetMacAddress(NetworkInterface ni, String name, Phaser
>>>> phaser) {
>>>>           this.ni = ni;
>>>>           this.threadName = name;
>>>>           this.startingGate = phaser;
>>>>       }
>>>>
>>>>       @Override
>>>>       public Exception call() {
>>>>           int count = 0;
>>>>           startingGate.arriveAndAwaitAdvance();
>>>>           try {
>>>>               for (int i = 0; i < NUM_ITERS; i++) {
>>>>                   ni.getMTU();
>>>>                   byte[] addr = ni.getHardwareAddress();
>>>>                   if (addr == null) {
>>>>                       System.out.println(threadName + ". mac id is
>>>> null");
>>>>                       failed = true;
>>>>                   }
>>>>                   count = count + 1;
>>>>                   if (count % 100 == 0) {
>>>>                       System.out.println(threadName + ". count is "
>>>> + count);
>>>>                   }
>>>>               }
>>>>           } catch (Exception ex) {
>>>>               System.out.println(threadName + ". Not expecting
>>>> exception:" + ex.getMessage());
>>>>               failed = true;
>>>>               return ex;
>>>>           }
>>>>           return null;
>>>>       }
>>>>
>>>>       static final Predicate<NetworkInterface> hasHardwareAddress =
>>>> ni -> {
>>>>           try {
>>>>               if (ni.getHardwareAddress() == null) {
>>>>                   System.out.println("Not testing null addr: " +
>>>> ni.getName());
>>>>                   return false;
>>>>               }
>>>>           } catch (Exception ex) {
>>>>               System.out.println("Not testing: " + ni.getName() +
>>>>                       " " + ex.getMessage());
>>>>           }
>>>>           return true;
>>>>       };
>>>>
>>>>       public static void main(String[] args) throws Exception {
>>>>           List<NetworkInterface> toTest =
>>>> NetworkInterface.networkInterfaces()
>>>>                           .filter(hasHardwareAddress)
>>>>                           .collect(Collectors.toList());
>>>>
>>>>           ExecutorService executor =
>>>> Executors.newFixedThreadPool(NUM_THREADS);
>>>>
>>>>           for (NetworkInterface ni : toTest) {
>>>>               Phaser startingGate = new Phaser(NUM_THREADS);
>>>>               System.out.println("Testing: " + ni.getName());
>>>>               List<Callable<Exception>> list = new ArrayList<>();
>>>>               for (int i = 0; i < NUM_THREADS; i++)
>>>>                   list.add(new GetMacAddress(ni, ni.getName() +
>>>> "-Thread-" + i, startingGate));
>>>>               List<Future<Exception>> futures =
>>>> executor.invokeAll(list);
>>>>               for (Future<Exception> f : futures) {
>>>>                   if (f.get() != null)
>>>>                       f.get().printStackTrace(System.out);
>>>>               }
>>>>               if (failed)
>>>>                   break;
>>>>           }
>>>>           executor.shutdownNow();
>>>>           if (!failed) {
>>>>               System.out.println("PASSED - Finished all threads");
>>>>           } else {
>>>>               throw new RuntimeException("Failed");
>>>>           }
>>>>       }
>>>> }
>>
>