Skip to content

Race condition on initial Karaf start corrupts config file #2805

Description

@olfuerniss

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.<init>(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:

<features name="karaf-decanter-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.4.0 http://karaf.apache.org/xmlns/features/v1.4.0">

    <feature name="decanter-common" version="${project.version}" description="Karaf Decanter API">
        <config name="org.apache.felix.eventadmin.impl.EventAdmin" append="true">
org.apache.felix.eventadmin.ThreadPoolSize=40
org.apache.felix.eventadmin.Timeout=0
org.apache.felix.eventadmin.IgnoreTimeout=org.apache.karaf.decanter.
        </config>
        <feature>eventadmin</feature>
      ....

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions