Race condition on initial Karaf start corrupts config file
- Dominant language
- Java
- Stars
- 712
- Forks
- 664
- Avg merge
- 2d 20m
- Merged PRs (30d)
- 84
Description
And the result are a lot of "Key [] must not be an empty string" errors in the log like this for nearly all cfg files:
```
2026-08-17T14:30:54,225 | ERROR | fileinstall-/home/bb/Documents/dev/karaf-5.1.0-SNAPSHOT/etc | fileinstall | 11 - org.apache.felix.fileinstall - 3.7.4 | Failed to install artifact: /home/bb/Documents/dev/karaf-5.1.0-SNAPSHOT/etc/jmx.acl.osgi.compendium.cm.cfg
java.lang.IllegalArgumentException: Key [] must not be an empty string
at org.apache.felix.cm.impl.CaseInsensitiveDictionary.checkKey(CaseInsensitiveDictionary.java:269)
at org.apache.felix.cm.impl.CaseInsensitiveDictionary.(CaseInsensitiveDictionary.java:73)
at org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy.cache(CachingPersistenceManagerProxy.java:171)
at org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy.getDictionaries(CachingPersistenceManagerProxy.java:209)
at org.apache.felix.cm.impl.ConfigurationManager.listConfigurations(ConfigurationManager.java:534)
at org.apache.felix.cm.impl.ConfigurationAdminImpl.listConfigurations(ConfigurationAdminImpl.java:190)
at org.apache.felix.fileinstall.internal.ConfigInstaller.findExistingConfiguration(ConfigInstaller.java:506)
at org.apache.felix.fileinstall.internal.ConfigInstaller.getConfiguration(ConfigInstaller.java:476)
at org.apache.felix.fileinstall.internal.ConfigInstaller.setConfig(ConfigInstaller.java:386)
at org.apache.felix.fileinstall.internal.ConfigInstaller.install(ConfigInstaller.java:192)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:950)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.install(DirectoryWatcher.java:884)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:489)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)
```
In our custom Karaf it happens only from time to time and is hard to reproduce. @grgrzybek (Grzegorz Grzybek) had a similar issue in ticket https://issues.apache.org/jira/browse/KARAF-7389. Unfortunately, he only fixed it for the case where the cfg file didn't exist yet. In our case, the cfg file already exists and is being updated. This leads to a race condition, and the cfg file becomes corrupt.
For us, only ONE cfg-file gets updated on the initial start of our custom Karaf and that is `[karaf]/etc/org.apache.felix.eventadmin.impl.EventAdmin.cfg`. This update happens due to the fact that we add Karaf-Decanter ('decanter-collector-log') to our boot features.
The default `[karaf]/etc/org.apache.felix.eventadmin.impl.EventAdmin.cfg` looks like this
```
################################################################################
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
org.apache.felix.eventadmin.AddTimestamp=true
org.apache.felix.eventadmin.AddSubject=true
```
The Karaf-Decanter extends the config file `[karaf]/etc/org.apache.felix.eventadmin.impl.EventAdmin.cfg` by 3 additional EventAdmin settings:
```
org.apache.felix.eventadmin.ThreadPoolSize=40
org.apache.felix.eventadmin.Timeout=0
org.apache.felix.eventadmin.IgnoreTimeout=org.apache.karaf.decanter.
eventadmin
....
```
When it comes to a race condition `[karaf]/etc/org.apache.felix.eventadmin.impl.EventAdmin.cfg` is corrupt and looks for example like this:
```
org.apache.felix.eventadmin.ThreadPoolSize = 40
org.apache.felix.eventadmin.Timeout = 0
org.apache.felix.eventadmin.IgnoreTimeout = org.apache.karaf.decanter.
=true
org.apache.felix.eventadmin.AddSubject=true
```
When everything is fine (most of the time), it looks like this:
```
################################################################################
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
org.apache.felix.eventadmin.AddTimestamp=true
org.apache.felix.eventadmin.AddSubject=true
org.apache.felix.eventadmin.Timeout = 0
org.apache.felix.eventadmin.ThreadPoolSize = 40
org.apache.felix.eventadmin.IgnoreTimeout = org.apache.karaf.decanter.
```
P.S. In our custom Karaf we can workaround a potential race condition, by providing a `[karaf]/etc/org.apache.felix.eventadmin.impl.EventAdmin.cfg` that already contains all settings so that no update of the file must be done.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the update path through the ConfigInstaller and DirectoryWatcher entry points shown in the stack trace, including how an existing configuration file is read and rewritten. Reproduce the initial-start race and add coverage that verifies the EventAdmin configuration remains valid and complete instead of containing a split key or value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100