Skip to content

Panick on log rotation on Windows #200

@lduchosal

Description

@lduchosal

Hello,

FimService panicked on windows today. Log file provide a hint at what happened.


2025-08-06T07:05:55.6435 [ERROR] thread '<unnamed>' panicked at '(log) Unable to open events log file.: Os { code: 32, kind: Uncategorized, message: "The process cannot access the file because it is being used by another process." }': src\monitorevent.rs:88
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: BuildSecurityDescriptorForSharingAccessEx
  16: BaseThreadInitThunk
  17: RtlUserThreadStart

2025-08-06T07:05:55.6556 [ERROR] thread 'FIM_HashScanner' panicked at '(hashevent::log) Unable to open events log file.: Os { code: 32, kind: Uncategorized, message: "The process cannot access the file because it is being used by another process." }': src\hashevent.rs:44
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: BaseThreadInitThunk
  18: RtlUserThreadStart

2025-08-06T07:05:55.7572 [INFO] File C:\ProgramData\fim\events.json rotated.

Here's what's happening:

Two different threads are trying to access the same log file (events.json) simultaneously, causing a file locking conflict.
Breaking Down the Errors
Error 1 - Main Monitor Thread:

Thread:
Location: src\monitorevent.rs:88
Issue: Cannot open the events log file

Error 2 - Hash Scanner Thread:

Thread: FIM_HashScanner
Location: src\hashevent.rs:44
Issue: Same file access problem

Key Error Details:

Error Code 32: Windows system error meaning "file is in use by another process"
File: C:\ProgramData\fim\events.json
Root Cause: Multiple threads trying to write and rotate the same log file without proper synchronization

The Core Problem

Fim implemented its own logging that miss critical feature such as thread synchronisation (?).

The Resolution

Use a standard logging library that support multi threading and can rotate log.

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