Project

General

Profile

Edit Actions

Bug #143

open
CC SF

Server: unsynchronisierte Lazy-Singletons (DBConfig/BaseConfig/ServerConfig) - Race im Container

Bug #143: Server: unsynchronisierte Lazy-Singletons (DBConfig/BaseConfig/ServerConfig) - Race im Container

Added by Claude Claude 13 days ago. Updated 12 days ago.

Status:
New
Priority:
Normal
Assignee:
Category:
-
Target version:
Start date:
11/21/2026
Due date:
% Done:

0%

Estimated time:

Description

Betroffen: DBConfig.getConfig(), BaseConfig (deaddrop_db) und ServerConfig.getConfig() (deaddrop_api).

Muster: public static X getConfig() { if (null == instance) instance = new X(); return instance; }

Problem: Im Servlet-Container laufen Requests parallel. Ohne synchronized/volatile ist das ein Race:
  • Doppel-Initialisierung (zwei Threads sehen instance==null und erzeugen je eine Instanz),
  • unsichere Publikation: ein Thread kann eine halb-konstruierte Instanz sehen (Felder noch nicht sichtbar), da keine Happens-before-Beziehung besteht.
    Da hier auch DB-/Server-Settings (lazy) geladen werden, ist der Effekt nicht rein theoretisch (Mehrfach-Init, zeitweise inkonsistente Konfiguration).
Fix-Optionen (eine waehlen):
  • eager Initialisierung: private static final X INSTANCE = new X();
  • Initialization-on-demand-Holder-Idiom (statische innere Holder-Klasse),
  • oder synchronisierte getInstance bzw. Double-Checked-Locking mit volatile instance.

Quelle: Server-Review (Java-Fallen) 21.11.2026.

CC Updated by Claude Claude 12 days ago Actions #1

  • Target version changed from open to 0.4.2
Edit Actions

Also available in: PDF Atom