Skip to content
Merged
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
4 changes: 4 additions & 0 deletions client/conf/server.properties.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ access.log=/var/log/cloudstack/management/access.log

# The deployment mode for the extensions
extensions.deployment.mode=@EXTENSIONSDEPLOYMENTMODE@

# Thread pool configuration
#threads.min=10
#threads.max=500
18 changes: 16 additions & 2 deletions client/src/main/java/org/apache/cloudstack/ServerDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class ServerDaemon implements Daemon {
private static final int DEFAULT_REQUEST_CONTENT_SIZE = 1048576;
private static final String REQUEST_MAX_FORM_KEYS_KEY = "request.max.form.keys";
private static final int DEFAULT_REQUEST_MAX_FORM_KEYS = 5000;
private static final String THREADS_MIN = "threads.min";
private static final String THREADS_MAX = "threads.max";

////////////////////////////////////////////////////////
/////////////// Server Configuration ///////////////////
Expand All @@ -106,6 +108,8 @@ public class ServerDaemon implements Daemon {
private String keystoreFile;
private String keystorePassword;
private String webAppLocation;
private int minThreads;
private int maxThreads;

//////////////////////////////////////////////////
/////////////// Public methods ///////////////////
Expand Down Expand Up @@ -147,6 +151,8 @@ public void init(final DaemonContext context) {
setSessionTimeout(Integer.valueOf(properties.getProperty(SESSION_TIMEOUT, "30")));
setMaxFormContentSize(Integer.valueOf(properties.getProperty(REQUEST_CONTENT_SIZE_KEY, String.valueOf(DEFAULT_REQUEST_CONTENT_SIZE))));
setMaxFormKeys(Integer.valueOf(properties.getProperty(REQUEST_MAX_FORM_KEYS_KEY, String.valueOf(DEFAULT_REQUEST_MAX_FORM_KEYS))));
setMinThreads(Integer.valueOf(properties.getProperty(THREADS_MIN, "10")));
setMaxThreads(Integer.valueOf(properties.getProperty(THREADS_MAX, "500")));
Comment on lines +154 to +155
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing input validation for thread configuration values. The code should validate that minThreads > 0, maxThreads > 0, and minThreads <= maxThreads to prevent invalid thread pool configurations that could cause runtime issues.

Suggested change
setMinThreads(Integer.valueOf(properties.getProperty(THREADS_MIN, "10")));
setMaxThreads(Integer.valueOf(properties.getProperty(THREADS_MAX, "500")));
setMaxThreads(Integer.valueOf(properties.getProperty(THREADS_MAX, "500")));
// Validate thread configuration
if (minThreads <= 0) {
logger.warn("Invalid minThreads value (" + minThreads + "). Setting to default (10).");
setMinThreads(10);
}
if (maxThreads <= 0) {
logger.warn("Invalid maxThreads value (" + maxThreads + "). Setting to default (500).");
setMaxThreads(500);
}
if (minThreads > maxThreads) {
logger.warn("minThreads (" + minThreads + ") is greater than maxThreads (" + maxThreads + "). Setting minThreads to maxThreads.");
setMinThreads(maxThreads);
}

Copilot uses AI. Check for mistakes.
} catch (final IOException e) {
logger.warn("Failed to read configuration from server.properties file", e);
} finally {
Expand All @@ -164,8 +170,8 @@ public void init(final DaemonContext context) {
public void start() throws Exception {
// Thread pool
final QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(10);
threadPool.setMaxThreads(500);
threadPool.setMinThreads(minThreads);
threadPool.setMaxThreads(maxThreads);

// Jetty Server
server = new Server(threadPool);
Expand Down Expand Up @@ -394,4 +400,12 @@ public void setMaxFormContentSize(int maxFormContentSize) {
public void setMaxFormKeys(int maxFormKeys) {
this.maxFormKeys = maxFormKeys;
}

public void setMinThreads(int minThreads) {
this.minThreads = minThreads;
}

public void setMaxThreads(int maxThreads) {
this.maxThreads = maxThreads;
}
}
Loading