| Previous | Next |
| ERROR_CONTINUE | ERROR_NO_MORE_DEVICES |
ERROR_ALREADY_INITIALIZED
The component has already completed initialization.
ERROR_ALREADY_INITIALIZED is Win32 error 1247 (0x4DF). It indicates a lifecycle violation: the caller invoked an initialization operation after the target object, subsystem, or provider was already initialized. The code does not prove that the existing instance is healthy or configured the way the new caller expected.
Typical causes
- two startup paths race and both believe they own initialization
- a retry wrapper repeats initialization after the first call actually succeeded
- shutdown clears some resources but leaves the state flag initialized
- a plug-in host initializes a process-wide library once per plug-in
- configuration changes are incorrectly applied by calling the initial setup function again
State evidence
Record the component instance, process and thread IDs, first successful initialization call, requested options, reference count, and shutdown history. Logs should distinguish “initialized with identical settings” from “initialized with incompatible settings.” Without that distinction, operators may mistake a configuration conflict for a harmless duplicate call.
Diagnostic sequence
Find the first transition into the initialized state and confirm which owner performed it. Examine static constructors, service startup, plug-in loading, lazy initialization, and reconnect code for duplicate entry paths. If initialization is process-wide, verify that object-level wrappers do not each invoke it independently.
Then inspect the cleanup contract. A failed partial shutdown can leave a state flag set even after handles were released, producing 1247 followed by use-after-close failures. Conversely, clearing the flag too early can allow two concurrent initializers into resources that require single ownership.
Correct handling
If repeated initialization is explicitly allowed and the active configuration matches, return the existing object or increment a documented reference count. Otherwise, fail with a message that includes the original configuration and the conflicting request. Do not silently tear down a process-wide subsystem while other users may still depend on it.
Design recommendations
- use a synchronized state machine with uninitialized, initializing, initialized, and stopping states
- store the result of one-time initialization for all waiting threads
- separate reconfiguration from first-time setup
- make shutdown ownership and reference counting explicit
Example
A plug-in framework loads three modules that share one telemetry library. Each module calls the library initializer, and the second receives 1247 with a different output directory. The host should initialize telemetry once, publish the resulting handle, and reject later conflicting configuration through a dedicated reconfiguration path.
References
- Microsoft: System Error Codes (1000–1299)
- Microsoft: One-Time Initialization
- Microsoft: InitOnceExecuteOnce function
Looking for a different code? Search another status or error code.
