microsoft / ApplicationInsights-Java

Application Insights for Java
http://aka.ms/application-insights
Other
296 stars 199 forks source link

ApplicationInsights-agent-3.4.12 generate otel-agentXXX/agent.jar files in windows/Temp which consumes all memory #3183

Open fred-sudo opened 1 year ago

fred-sudo commented 1 year ago

Expected behavior

temp generated agent.jar file in windows/Temp folder should be removed automatically because the programmer did not write or program to create the jar file.

Actual behavior

The file agent.jar in windows/Temp/otel-agentXXXXXXXXXX/agent.jar is not getting deleted. It creates an out-of-memory issue on the server. Admin is not supposed to write batch process to write windows based another batch script to delete these files

To Reproduce

any spring boot-based batch process using application-insights lib 3.4.12 will reproduce the same issue

System information

Please provide the following information:

Logs

logs are just file but in windows/Temp/otel-agentXXXXXXXX/agent.jar files are creating pollution. there is a well-known issue of Windows OS java can not delete jar file bugs.openjdk.org/browse/JDK-8219681. but using RandomAccessFile class of standard jdk lib it must be possible to delete the file. RunTime.getRuntime.addShutdownHook() or deleteonExit() definitely should work. Or ApplicationInsights-agent lib has to manage this without creating an agent.jar file

Screenshots

Not possible to bring screenshots here

jeanbisutti commented 1 year ago

Hi @fred-sudo Thank you for having reported this issue. Application Insights runtime attach component uses a runtime attach OpenTelemetry component. file.deleteOnExit() is invoked (deleteOnExit() uses a JVM shutdown hook behind the scene). We could look at this issue on Microsoft side. Would you be interested in fixing this issue on the OTel side? In this case, we could help you contribute to the OTel component.

fred-sudo commented 1 year ago

Thank you so much I would be happy to fix the issue on OTel side. I can work on [private static void deleteTempDirOnJvmExit(] with the other options mentioned. my observation -- this issue is on the Windows server only. for my laptop OS it could not see these jar files in Windows/Temp folder.