Menu

#343 Crash on app exit

v1.2.0
closed
5
2017-07-12
2017-06-23
Ralf Sieger
No

log4cplus:

  • 1.2.0
  • Visual Studio 2012
  • config: release and debug
  • windows 10, i7 4770

client:

  • 32 bit Java 7 application
  • log4cplus as dll
  • log4cplus.lib and log4cplusD.lib
  • multibyte chars
  • see attached logfiles
  • client DLL compile settings: no MFC, no ATL, multibyte charset, /MDd and /MD

We use log4cplus in an custom C++ dll which itself gets dynamically loaded in java program.
during the runtime everything works ok.
At application exit we see an java hotspot error (see logs).
This happens with and without calling log4cplus::Logger::shutdown();
The problem also occurs if nothing but log4cplus::initialize(); and log4cplus::Logger::shutdown(); are called.

From the hotspot error it looks like an cleanup issue:

Stack: [0x46760000,0x467b0000],  sp=0x467aee5c,  free space=315k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ntdll.dll+0xecc94]
C  [ntdll.dll+0x9683a]
C  [KERNEL32.DLL+0x1dbb9]
C  [MSVCR110.dll+0x9fa77]
C  [MSVCR110.dll+0x4defc]
C  [MSVCR110.dll+0x4f4cf]
C  [MSVCR110.dll+0x2431b]
C  [MSVCR110.dll+0x243dc]
C  [MSVCR110.dll+0x16629]
C  [MSVCR110.dll+0x6a312]
C  [MSVCP110.dll+0x2e2d8]
C  [MSVCP110.dll+0x2e47e]
C  [log4cplus.dll+0x229b]  log4cplus::thread::SyncGuard<log4cplus::thread::Mutex>::SyncGuard<log4cplus::thread::Mutex>+0x2b
C  [log4cplus.dll+0x3f1dd]  log4cplus::spi::ObjectRegistryBase::clear+0x2d
C  [log4cplus.dll+0x14225]  log4cplus::`anonymous namespace'::DefaultContext::~DefaultContext+0x45
C  [log4cplus.dll+0x143a5]  log4cplus::`anonymous namespace'::destroy_default_context::~destroy_default_context+0x25
C  [log4cplus.dll+0x559cd]  log4cplus::`anonymous namespace'::`dynamic atexit destructor for 'destroy_default_context_''+0xd
C  [log4cplus.dll+0x4e002]  _CRT_INIT+0xc1
C  [log4cplus.dll+0x4e228]  __DllMainCRTStartup+0xcf
C  [log4cplus.dll+0x4e152]  _DllMainCRTStartup+0x1c
2 Attachments

Discussion

  • Václav Haisman

    Václav Haisman - 2017-07-10
    • labels: --> java
    • assigned_to: Václav Haisman
     
  • Václav Haisman

    Václav Haisman - 2017-07-10
    • labels: java --> java, v1.2.0
     
  • Václav Haisman

    Václav Haisman - 2017-07-10

    I am not sure what to think about this. Could you please try HEAD of 1.2.x branch or 2.0.x branch? There have been some initialization and shutdown related changes since the 1.2.0 release. If just using newer log4cplus does not help, could you please try and run your app/java under a debugger with Microsoft symbols path set up so that we can see more of the contex, if at all possible?

     
  • Ralf Sieger

    Ralf Sieger - 2017-07-11

    Tried it with log4cplus-1.2.1-rc1
    Same result. But small difference in the call stack.

    I've also attached the MSVC Debugger with log4cplus symbols and got:

    First-chance exception at 0x7560A9F2 in javaw.exe: Microsoft C++ exception: Concurrency::scheduler_resource_allocation_error at memory location 0x46BFEF34.
    Ausnahme (erste Chance) bei 0x58E2591B (jvm.dll) in javaw.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00000010

     
  • Václav Haisman

    Václav Haisman - 2017-07-11

    Thank you for the additional information, I think I now understand the situation. We have seen this before. The issue is with how are C++11 synchornization primitives implemented in Visual Studio.

    As a stop gap measure, you can modify the log4cplus source like the following diff, for 1.2.x branch:

    diff --git a/include/log4cplus/config/win32.h b/include/log4cplus/config/win32.h
    index 8e5175cd..aa4b0202 100644
    --- a/include/log4cplus/config/win32.h
    +++ b/include/log4cplus/config/win32.h
    @@ -162,7 +162,7 @@
     #  endif
     #  if _MSC_VER >= 1700
     #    define LOG4CPLUS_HAVE_CXX11_ATOMICS
    -#    define LOG4CPLUS_WITH_CXX11_THREADS
    +//#    define LOG4CPLUS_WITH_CXX11_THREADS
     #  endif
     #endif
    

    This will however not apply on 2.0.x branch because I have removed the non-C++11 implementations of synchornization primitives. I will either have to re-introduce them or...I do not know what else yet.

    I am keeping this open to remind me about this issue.

     
  • Václav Haisman

    Václav Haisman - 2017-07-11
    • labels: java, v1.2.0 --> java, v1.2.0, c++11, threads, mutex
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,24 +1,27 @@
     log4cplus:
    -- 1.2.0
    -- Visual Studio 2012
    -- config: release and debug
    -- windows 10, i7 4770
    +
    +* 1.2.0
    +* Visual Studio 2012
    +* config: release and debug
    +* windows 10, i7 4770
    
     client:
    -- 32 bit Java 7 application
    -- log4cplus as dll
    -- log4cplus.lib and log4cplusD.lib
    -- multibyte chars
    -- see attached logfiles
    -- client DLL compile settings: no MFC, no ATL, multibyte charset, /MDd and /MD
    +
    +* 32 bit Java 7 application
    +* log4cplus as dll
    +* log4cplus.lib and log4cplusD.lib
    +* multibyte chars
    +* see attached logfiles
    +* client DLL compile settings: no MFC, no ATL, multibyte charset, /MDd and /MD
    
     We use log4cplus in an custom C++ dll which itself gets dynamically loaded in java program.
     during the runtime everything works ok.
     At application exit we see an java hotspot error (see logs). 
    -This happens with and without calling log4cplus::Logger::shutdown();
    -The problem also occurs if nothing but log4cplus::initialize(); and log4cplus::Logger::shutdown(); are called.
    +This happens with and without calling `log4cplus::Logger::shutdown();`
    +The problem also occurs if nothing but `log4cplus::initialize();` and `log4cplus::Logger::shutdown();` are called.
    
     From the hotspot error it looks like an cleanup issue:
    +
     ~~~
     Stack: [0x46760000,0x467b0000],  sp=0x467aee5c,  free space=315k
     Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    
     
  • Václav Haisman

    Václav Haisman - 2017-07-11

    I have pushed bd27044f35 to 1.2.x branch to work around this for 1.2.x. It should actually be OK on 2.0.x branch as only Visual Studio 2015 and later is supported there.

     
  • Ralf Sieger

    Ralf Sieger - 2017-07-12

    Hi Václav,
    I've tried your patch with log4cplus-1.2.1-rc2 and it seems this did the trick!
    Thank you very much for the quick fix!

     
  • Václav Haisman

    Václav Haisman - 2017-07-12
    • labels: java, v1.2.0, c++11, threads, mutex --> java, v1.2.0, c++11, threads, mutex, fixed
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.