RFR: 8268361: Fix the infinite loop in next_line [v2]

UncleNine github.com+1964054+unclenine at openjdk.java.net
Tue Jun 8 16:24:18 UTC 2021


On Tue, 8 Jun 2021 06:39:12 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> src/jdk.management/linux/native/libmanagement_ext/UnixOperatingSystem.c line 70:
>> 
>>> 68:     do {
>>> 69:         c = fgetc(f);
>>> 70:     } while(c != '\n' && c != EOF);
>> 
>> Style nit: please add space before (
>
> It is not obvious to me that the caller of next_line will handle the fact that we have hit EOF?

In my case,  it happened in the container environment.
the /proc filesystem of the container is provided by  lxcfs, but a lxcfs bug may make the /proc/stat mount point change, then  the file descriptor is different and fgetc function returns an EOF on error,  But c != '\n' is true and it leads to the  infinit loop.
Below are our flamegraph in the production , it happends on serveral frameworks(micrometer, elasticsearch..)which use the api "sun/management/OperatingSystemImpl.getSystemCpuLoad"
![107140246-bb490f80-695b-11eb-9f62-0116079f4f4a](https://user-images.githubusercontent.com/1964054/121218982-d5690f00-c8b5-11eb-8c1e-e39f2f2bc6a5.jpg)

-------------

PR: https://git.openjdk.java.net/jdk/pull/4378


More information about the serviceability-dev mailing list