Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
uses: danipaniii/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
sinceTag: ${{ steps.previoustag.outputs.tag }}
sinceTag: 2.7.0
dateFormat:
maxIssues: 500
unreleased: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -144,7 +145,7 @@ private static Path recycleJarFileWithLock(String resourcePath, Path jarPath) th

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

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

while (System.currentTimeMillis() < end) {
FileLock lock = lockChannel.tryLock();
if (lock != null) return lock;

try {
FileLock lock = lockChannel.tryLock();
if (lock != null) return lock;
} catch (OverlappingFileLockException e) {
System.err.println("OverlappingFileLock occured." + e);
throw new IOException(e);
}
try {
Thread.sleep(retryDelay);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -218,6 +223,30 @@ private static boolean isRecyclingEnabled() {
return "true".equalsIgnoreCase(isRecyclingEnabledValue);
}

/**
* If the recycling of jars is enabled, the timeout for the recycling/file locking operation can be set.
* The value has to be a non-zero non-negative long, if the conditions are not met, it defaults to 3000ms.
*
* @return long, either the default of 3000ms or the value of the timeout property
*/
private static long getJarRecyclingTimeout() {
String recyclingTimeout = null != System.getProperty(AgentProperties.RECYCLE_JARS_TIMEOUT_PROPERTY) ?
System.getProperty(AgentProperties.RECYCLE_JARS_TIMEOUT_PROPERTY) : System.getenv(AgentProperties.RECYCLE_JARS_TIMEOUT_ENV_PROPERTY);

final long DEFAULT_RECYCLE_TIMEOUT = 3000;

if (recyclingTimeout == null) return DEFAULT_RECYCLE_TIMEOUT;

try {
long recyclingTimeoutLong = Long.parseUnsignedLong(recyclingTimeout);
if (recyclingTimeoutLong <= 0) throw new NumberFormatException();
return recyclingTimeoutLong;
} catch (NumberFormatException nfe) {
System.err.println("Jar Recycling Timeout property must be a non-negative non-zero long, therefore reverting to default timeout of 3000ms.");
return DEFAULT_RECYCLE_TIMEOUT;
}
}

/**
* Reads the current agent version from the ocelot-version.info file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class AgentProperties {

public static final String RECYCLE_JARS_ENV_PROPERTY = "INSPECTIT_RECYCLE_JARS";

public static final String RECYCLE_JARS_TIMEOUT_PROPERTY = "inspectit.recycle-jars-timeout";

public static final String RECYCLE_JARS_TIMEOUT_ENV_PROPERTY = "INSPECTIT_RECYCLE_JARS_TIMEOUT";

public static final String INSPECTIT_TEMP_DIR_PROPERTY = "inspectit.temp-dir";

public static final String INSPECTIT_TEMP_DIR_ENV_PROPERTY = "INSPECTIT_TEMP_DIR";
Expand All @@ -27,6 +31,7 @@ public class AgentProperties {
static {
PROPERTY_NAMES.add(START_DELAY_PROPERTY);
PROPERTY_NAMES.add(RECYCLE_JARS_PROPERTY);
PROPERTY_NAMES.add(RECYCLE_JARS_TIMEOUT_PROPERTY);
PROPERTY_NAMES.add(INSPECTIT_TEMP_DIR_PROPERTY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,22 @@ By default, these files will be created temporarily at runtime.
Each agent will create these new JAR files for itself inside the temporary directory.
When you are running multiple agents on the same machine, this would consume additional storage space.
Thus, you can configure the agent to recycle such JAR files via the system property `inspectit.recycle-jars`
or the OS environment variable `INSPECTIT_RECYCLE_JARS`.
or the OS environment variable `INSPECTIT_RECYCLE_JARS`. The timeout for this recycling operation can be set via
system property `inspectit.recycle-jars-timeout` or the OS environment variable `INSPECTIT_RECYCLE_JARS_TIMEOUT`

```
-Dinspectit.recycle-jars=true
```

The agent will look inside ``${temporary-directory}/inspectit-ocelot/{inspectit-ocelot-version}`` for JAR files.
If no files have been found, the agent will create new ones, which can also be used by other agents.
**These files will not be deleted after the shutdown of the agent.** Thus, when you are updating your agent version,
**These files will not be deletfed after the shutdown of the agent.** Thus, when you are updating your agent version,
you will have to delete the JAR files from the previous version manually.

```
-Dinspectit.recycle-jars-timeout=3000
```

During JAR recycling, the agent attempts to lock the JARs during startup. However, when starting multiple JVMs at the
same time, it can occur that the JVMs lock each other out, leading to an error. This parameter allows changing
the timeout of the file lock retry to allow for more retries, making startup more robust. The default is set to 3000ms.
Loading