Skip to content

Fix Missing log file error on startup#753

Merged
dnzbk merged 7 commits intodevelopfrom
fix/log-filepath
Mar 13, 2026
Merged

Fix Missing log file error on startup#753
dnzbk merged 7 commits intodevelopfrom
fix/log-filepath

Conversation

@dnzbk
Copy link
Copy Markdown
Collaborator

@dnzbk dnzbk commented Mar 11, 2026

Description

  • Fixed an error with missing log file

Testing

  • macOS Tahoe
  • Windows 11

@dnzbk dnzbk requested a review from luckedea March 11, 2026 06:20
@dnzbk dnzbk changed the title Fix Missing log file error Fix Missing log file error on startup Mar 11, 2026
@dnzbk dnzbk force-pushed the fix/log-filepath branch from 3e6c79f to a2affe8 Compare March 12, 2026 11:35
luckedea
luckedea previously approved these changes Mar 13, 2026
@dnzbk dnzbk merged commit 1fdf3ae into develop Mar 13, 2026
9 checks passed
@dnzbk dnzbk deleted the fix/log-filepath branch March 13, 2026 09:27
@bket
Copy link
Copy Markdown
Contributor

bket commented Mar 14, 2026

@dnzbk, @luckedea, I am a bit late to the party, but on OpenBSD a regression was introduced that causes NZBGet to crash during startup.

This crash is caused by a recursive lock violation and uninitialized mutex access during the early boot sequence. In Log.cpp, Log::Filelog already acquires m_logMutex before calling Log::RotateLog. By adding a second Guard inside RotateLog(), the thread attempts to lock a non-recursive mutex it already owns, triggering an immediate abort by OpenBSD’s strict rthreads library. Furthermore, because this occurs during NZBGet::Init while the global g_Log object is still being initialized, the threading library detects an invalid mutex state (as seen by the this=0x0 in the GDB trace) and terminates the process.

(gdb) bt
#0  thrkill () at /tmp/-:2
#1  0xbabae82f7b63f8bd in ?? ()
#2  0x000007a56756854b in _libc_abort () at /usr/src/lib/libc/stdlib/abort.c:51
#3  0x000007a56759fa7a in _rthread_mutex_trylock (mutex=0x7a55d8f6a00, trywait=0, abs=0x0)
    at /usr/src/lib/libc/thread/rthread_mutex.c:117
#4  _rthread_mutex_timedlock (mutexp=<optimized out>, trywait=0, abs=0x0, timed=<optimized out>)
    at /usr/src/lib/libc/thread/rthread_mutex.c:167
#5  0x000007a509cc8dab in std::__1::__libcpp_mutex_lock[abi:ne190107](pthread_mutex volatile**) (__m=0x0)
    at /usr/src/gnu/lib/libcxx/../../../gnu/llvm/libcxx/include/__thread/support/pthread.h:95
#6  std::__1::mutex::lock (this=0x0) at /usr/src/gnu/lib/libcxx/../../../gnu/llvm/libcxx/src/mutex.cpp:29
#7  0x000007a2b81b9d07 in Mutex::Lock (this=0x7a55d8eb840)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/util/Thread.h:33
#8  Guard::Guard (mutex=..., this=<optimized out>)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/util/Thread.h:46
#9  Log::RotateLog (this=0x7a55d8eb840)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/util/Log.cpp:372
#10 0x000007a2b81b98bc in Log::Filelog (this=0x7a55d8eb840, msg=<optimized out>)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/util/Log.cpp:85
#11 0x000007a2b81ba409 in error (msg=<optimized out>)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/util/Log.cpp:217
#12 0x000007a2b8087b27 in NZBGet::BootConfig (this=0x7a55d908e00)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/main/nzbget.cpp:498
#13 0x000007a2b8086b9e in NZBGet::Init (this=0x7a55d908e00)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/main/nzbget.cpp:290
#14 0x000007a2b8088f06 in NZBGet::Run (this=0x0, reload=6)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/main/nzbget.cpp:787
#15 0x000007a2b808648d in RunMain ()
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/main/nzbget.cpp:1119
#16 0x000007a2b8086374 in main (argc=2, argv=0x7a62983f8d38, argp=0x7a62983f8d50)
    at /usr/ports/pobj/nzbget-26.0.20260313/nzbget-749d9e3c33971317b15597b9b882ebb7ecdfd0c5/daemon/main/nzbget.cpp:171

Removing the redundant Guard from RotateLog() resolves the issue because the method is a private helper that is only ever reached while the caller holds the necessary lock or while the application is still single-threaded.

--- daemon/util/Log.cpp.orig
+++ daemon/util/Log.cpp
@@ -368,11 +368,8 @@ void Log::RotateLog()
        fullFilename.Format("%s%c%s-%i-%.2i-%.2i%s", *directory, PATH_SEPARATOR,
                baseName, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, *baseExt);

-       {
-               Guard guard(m_logMutex);
-               m_logFilename = fullFilename;
-               m_logFilePath = fs::u8path(m_logFilename);
-       }
+       m_logFilename = (const char*)fullFilename;
+       m_logFilePath = fs::u8path(m_logFilename);
 }

@dnzbk
Copy link
Copy Markdown
Collaborator Author

dnzbk commented Mar 14, 2026

@bket Yes, exactly. You are spot on. I finished working on the exact same solution on my end. I'll be pushing the updated code shortly. Thanks for looking into it.

dnzbk added a commit that referenced this pull request Mar 14, 2026
@dnzbk
Copy link
Copy Markdown
Collaborator Author

dnzbk commented Mar 14, 2026

@bket I've put in my fixes, so could you help me verify it works properly now on OpenBSD? Unfortunately, I don't have a build for you, so could you please test my dev branch feature/par2-turbo?
This branch includes the logging thread-safety refactor, the Par2-Turbo v1.4.0 update, and the switch to RapidYenc. Your input would be very helpful for me!

@bket
Copy link
Copy Markdown
Contributor

bket commented Mar 14, 2026

@dnzbk, build- and run-tested the feature/par2-turbo branch on OpenBSD current (amd64). Issue has been resolved. Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing log file error on startup Show in Windows Explorer -> Log-File" fails to locate the file when WriteLog is set to "Rotate" or "Reset"

3 participants