Skip to content

Commit 642470a

Browse files
arile01BohnAriane
authored
Hotfix Release 2.7.1 (#1865)
* Attempt to fix OverlappingFileLock Issues, added customizable filelock timeout * Manually setting previous release tag in release action * Added Documentation for Release 2.7.1 * Removed temporary version from release workflow --------- Co-authored-by: Bohn <tobias.bohn@cgi.com> Co-authored-by: Ariane <ariane.kraus@cgi.com>
1 parent a9bd839 commit 642470a

File tree

21 files changed

+2538
-6
lines changed

21 files changed

+2538
-6
lines changed

inspectit-ocelot-agent/src/main/java/rocks/inspectit/ocelot/agent/AgentJars.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.*;
66
import java.nio.channels.FileChannel;
77
import java.nio.channels.FileLock;
8+
import java.nio.channels.OverlappingFileLockException;
89
import java.nio.charset.StandardCharsets;
910
import java.nio.file.Files;
1011
import java.nio.file.Path;
@@ -144,7 +145,7 @@ private static Path recycleJarFileWithLock(String resourcePath, Path jarPath) th
144145

145146
try (RandomAccessFile lockFile = new RandomAccessFile(lockPath.toFile(), "rw");
146147
FileChannel lockChannel = lockFile.getChannel();
147-
FileLock lock = acquireLock(lockChannel, 1500, 50)
148+
FileLock lock = acquireLock(lockChannel, getJarRecyclingTimeout(), 50)
148149
) {
149150
if (lock == null) throw new IOException("Could not acquire lock for: " + lockPath);
150151

@@ -167,9 +168,13 @@ private static FileLock acquireLock(FileChannel lockChannel, long timeout, long
167168
long end = System.currentTimeMillis() + timeout;
168169

169170
while (System.currentTimeMillis() < end) {
170-
FileLock lock = lockChannel.tryLock();
171-
if (lock != null) return lock;
172-
171+
try {
172+
FileLock lock = lockChannel.tryLock();
173+
if (lock != null) return lock;
174+
} catch (OverlappingFileLockException e) {
175+
System.err.println("OverlappingFileLock occured." + e);
176+
throw new IOException(e);
177+
}
173178
try {
174179
Thread.sleep(retryDelay);
175180
} catch (InterruptedException e) {
@@ -218,6 +223,30 @@ private static boolean isRecyclingEnabled() {
218223
return "true".equalsIgnoreCase(isRecyclingEnabledValue);
219224
}
220225

226+
/**
227+
* If the recycling of jars is enabled, the timeout for the recycling/file locking operation can be set.
228+
* The value has to be a non-zero non-negative long, if the conditions are not met, it defaults to 3000ms.
229+
*
230+
* @return long, either the default of 3000ms or the value of the timeout property
231+
*/
232+
private static long getJarRecyclingTimeout() {
233+
String recyclingTimeout = null != System.getProperty(AgentProperties.RECYCLE_JARS_TIMEOUT_PROPERTY) ?
234+
System.getProperty(AgentProperties.RECYCLE_JARS_TIMEOUT_PROPERTY) : System.getenv(AgentProperties.RECYCLE_JARS_TIMEOUT_ENV_PROPERTY);
235+
236+
final long DEFAULT_RECYCLE_TIMEOUT = 3000;
237+
238+
if (recyclingTimeout == null) return DEFAULT_RECYCLE_TIMEOUT;
239+
240+
try {
241+
long recyclingTimeoutLong = Long.parseUnsignedLong(recyclingTimeout);
242+
if (recyclingTimeoutLong <= 0) throw new NumberFormatException();
243+
return recyclingTimeoutLong;
244+
} catch (NumberFormatException nfe) {
245+
System.err.println("Jar Recycling Timeout property must be a non-negative non-zero long, therefore reverting to default timeout of 3000ms.");
246+
return DEFAULT_RECYCLE_TIMEOUT;
247+
}
248+
}
249+
221250
/**
222251
* Reads the current agent version from the ocelot-version.info file
223252
*

inspectit-ocelot-bootstrap/src/main/java/rocks/inspectit/ocelot/bootstrap/AgentProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public class AgentProperties {
1717

1818
public static final String RECYCLE_JARS_ENV_PROPERTY = "INSPECTIT_RECYCLE_JARS";
1919

20+
public static final String RECYCLE_JARS_TIMEOUT_PROPERTY = "inspectit.recycle-jars-timeout";
21+
22+
public static final String RECYCLE_JARS_TIMEOUT_ENV_PROPERTY = "INSPECTIT_RECYCLE_JARS_TIMEOUT";
23+
2024
public static final String INSPECTIT_TEMP_DIR_PROPERTY = "inspectit.temp-dir";
2125

2226
public static final String INSPECTIT_TEMP_DIR_ENV_PROPERTY = "INSPECTIT_TEMP_DIR";
@@ -27,6 +31,7 @@ public class AgentProperties {
2731
static {
2832
PROPERTY_NAMES.add(START_DELAY_PROPERTY);
2933
PROPERTY_NAMES.add(RECYCLE_JARS_PROPERTY);
34+
PROPERTY_NAMES.add(RECYCLE_JARS_TIMEOUT_PROPERTY);
3035
PROPERTY_NAMES.add(INSPECTIT_TEMP_DIR_PROPERTY);
3136
}
3237

inspectit-ocelot-documentation/docs/configuration/start-configuration.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,22 @@ By default, these files will be created temporarily at runtime.
5252
Each agent will create these new JAR files for itself inside the temporary directory.
5353
When you are running multiple agents on the same machine, this would consume additional storage space.
5454
Thus, you can configure the agent to recycle such JAR files via the system property `inspectit.recycle-jars`
55-
or the OS environment variable `INSPECTIT_RECYCLE_JARS`.
55+
or the OS environment variable `INSPECTIT_RECYCLE_JARS`. The timeout for this recycling operation can be set via
56+
system property `inspectit.recycle-jars-timeout` or the OS environment variable `INSPECTIT_RECYCLE_JARS_TIMEOUT`
5657

5758
```
5859
-Dinspectit.recycle-jars=true
5960
```
6061

6162
The agent will look inside ``${temporary-directory}/inspectit-ocelot/{inspectit-ocelot-version}`` for JAR files.
6263
If no files have been found, the agent will create new ones, which can also be used by other agents.
63-
**These files will not be deleted after the shutdown of the agent.** Thus, when you are updating your agent version,
64+
**These files will not be deletfed after the shutdown of the agent.** Thus, when you are updating your agent version,
6465
you will have to delete the JAR files from the previous version manually.
66+
67+
```
68+
-Dinspectit.recycle-jars-timeout=3000
69+
```
70+
71+
During JAR recycling, the agent attempts to lock the JARs during startup. However, when starting multiple JVMs at the
72+
same time, it can occur that the JVMs lock each other out, leading to an error. This parameter allows changing
73+
the timeout of the file lock retry to allow for more retries, making startup more robust. The default is set to 3000ms.

0 commit comments

Comments
 (0)