Skip to content

Commit

Permalink
Fix services sync
Browse files Browse the repository at this point in the history
Found by coverity.
  • Loading branch information
rmaucher committed Jan 16, 2024
1 parent 50c8d32 commit 14048a2
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions java/org/apache/catalina/core/StandardServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,18 +701,22 @@ public Service findService(String name) {
*/
@Override
public Service[] findServices() {
return services;
synchronized (servicesLock) {
return services.clone();
}
}

/**
* @return the JMX service names.
*/
public ObjectName[] getServiceNames() {
ObjectName[] onames = new ObjectName[services.length];
for (int i = 0; i < services.length; i++) {
onames[i] = ((StandardService) services[i]).getObjectName();
synchronized (servicesLock) {
ObjectName[] onames = new ObjectName[services.length];
for (int i = 0; i < services.length; i++) {
onames[i] = ((StandardService) services[i]).getObjectName();
}
return onames;
}
return onames;
}


Expand Down Expand Up @@ -961,8 +965,10 @@ protected void stopInternal() throws LifecycleException {
fireLifecycleEvent(CONFIGURE_STOP_EVENT, null);

// Stop our defined Services
for (Service service : services) {
service.stop();
synchronized (servicesLock) {
for (Service service : services) {
service.stop();
}
}

synchronized (utilityExecutorLock) {
Expand Down Expand Up @@ -1002,16 +1008,20 @@ protected void initInternal() throws LifecycleException {
globalNamingResources.init();

// Initialize our defined Services
for (Service service : services) {
service.init();
synchronized (servicesLock) {
for (Service service : services) {
service.init();
}
}
}

@Override
protected void destroyInternal() throws LifecycleException {
// Destroy our defined Services
for (Service service : services) {
service.destroy();
synchronized (servicesLock) {
for (Service service : services) {
service.destroy();
}
}

globalNamingResources.destroy();
Expand Down

0 comments on commit 14048a2

Please sign in to comment.