Thank-you for the helpful stack trace.

The Windows pn_selector_t and pn_io_t objects are intertwined but are
completely separate on Posix systems where the order of teardown is
unimportant.  It looks to me as if the selector is free'd too early by
both the reactor and messenger.  The window of time that is at risk is
presumably very small, depending on how many IO completions need
draining on shutdown and what other thread activity may use/reuse the
free'd selector memory.  This could explain why you see it in one build
type and not another.

I think the following patch may fix your problem.  Please try it and
report back.

Cliff

------------------------------------------------------------------------

--- proton/proton-c/src/windows/io.c    2016-08-16 06:02:21 -0700
+++ new/proton-c/src/windows/io.c    2016-10-19 16:19:21 -0700
@@ -90,8 +90,11 @@
 void pn_io_finalize(void *obj)
 {
   pn_io_t *io = (pn_io_t *) obj;
-  pn_error_free(io->error);
+  pn_selector_t *sel = io->iocp->selector;
   pn_free(io->iocp);
+  if (sel)
+    pn_decref(sel);
+  pn_error_free(io->error);
   WSACleanup();
 }

@@ -366,8 +369,10 @@

 pn_selector_t *pn_io_selector(pn_io_t *io)
 {
-  if (io->iocp->selector == NULL)
+  if (io->iocp->selector == NULL) {
     io->iocp->selector = pni_selector_create(io->iocp);
+    pn_incref(io->iocp->selector);
+  }
   return io->iocp->selector;
 }


On Tue, Oct 18, 2016 at 7:45 AM, Antoine Chevin
<antoine.che...@gmail.com> wrote:
> Hello,
>
> We tried to investigate more about the problem today.
>
> From what we understood from the ssl.exe test code:
> The test throws an exception on the on_transport_error() because the
> certificate is wrong. This triggers the destruction of the objects on the
> stack.
> Apparently, there is a memory corruption in iocpdesc_t structure:
> We are calling (selector)->triggered_list_tail->triggered_list_next while
> (selector)->triggered_list_tail is null [in triggered_list_add() in
> selector.c line 300].
> Therefore we have the crash.
>
> Can you help us find more info about the bug? The crash is very low level
> and we have not very much experience in the proton-c layer...
>
> Thank you,
> Regards,
> Antoine
>
>
>
> -----Original Message-----
> From: Adel Boutros [mailto:adelbout...@live.com]
> Sent: lundi 17 octobre 2016 19:30
> To: users@qpid.apache.org
> Subject: [Proton-c 0.14.0][Visual Studio 2013] Failing ssl unit test only
> in Debug mode
>
> Hello,
>
>
> We are compiling Proton-c 0.14.0 and its C++ bindings in 2 modes:
> RelWithDebInfo and Debug.
>
>
> For the RelWithDebInfo mode, all tests are green.
>
> For the Debug mode, we have a ssl test failing.
>
>
> We are using OpenSSL 1.0.2h. Swing and Cyrus are disabled (not found).
>
>
> Can you please help us find the issue?
>
>
> Test output
>
> --------------
>
> 18: ======================================================================
> 18: ERROR: test_ssl_bad_name (__main__.ContainerExampleTest)
> 18: ----------------------------------------------------------------------
> 18: Traceback (most recent call last):
> 18:   File "PATH_TO_PROTON_SOURCE_CODE/examples/cpp/example_test.py", line
> 375, in test_ssl_bad_name
> 18:     out = self.proc(["ssl", "-a", addr, "-c", self.ssl_certs_dir(),
> "-v", "fail"], skip_valgrind=True).wait_exit()
> 18:   File "PATH_TO_PROTON_SOURCE_CODE/examples/cpp/example_test.py", line
> 180, in wait_exit
> 18:     self.check_()
> 18:   File "PATH_TO_PROTON_SOURCE_CODE/examples/cpp/example_test.py", line
> 164, in check_
> 18:     raise self.error
> 18: ProcError: ['ssl.exe', '-a', 'amqps://127.0.0.1:12202/examples', '-c',
> 'PATH_TO_PROTON_SOURCE_CODE\\examples/cpp/ssl_certs', '-v', 'fail'] non-0
> exit, code=255
> 18: vvvvvvvvvvvvvvvv
> 18: certificate verification failed for host wrong_name_for_server
> 18:  : The target principal name is incorrect.
> 18: ^^^^^^^^^^^^^^^^
>
>
>
> Command
>
> ------------------
>
> build_dir\Debug\examples\cpp\Debug\ssl.exe -c
> PATH_TO_PROTON_SOURCE_CODE\\examples/cpp/ssl_certs -v fail
>
>
> Output
>
> -------------
>
> certificate verification failed for host wrong_name_for_server
>  : The target principal name is incorrect.
>
>
> Exception in Visual Studio 2013
>
> ----------------------------------------
>
> Unhandled exception at 0x000007FB345782B2 (qpid-protond.dll) in ssl.exe:
> 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF
>
>
> Stack
>
> ------------------
>
>> qpid-protond.dll!triggered_list_add(pn_selector_t * selector, iocpdesc_t
> * iocpd) Line 300 C++
>   qpid-protond.dll!pni_events_update(iocpdesc_t * iocpd, int events) Line
> 324 C++
>   qpid-protond.dll!complete_read(read_result_t * result, unsigned long
> xfer_count, HRESULT status) Line 666 C++
>   qpid-protond.dll!complete(iocp_result_t * result, bool success, unsigned
> long num_transferred) Line 868 C++
>   qpid-protond.dll!pni_iocp_drain_completions(iocp_t * iocp) Line 888 C++
>   qpid-protond.dll!iocp_map_close_all(iocp_t * iocp) Line 1044 C++
>   qpid-protond.dll!pni_iocp_finalize(void * obj) Line 1151 C++
>   qpid-protond.dll!pn_class_decref(const pn_class_t * clazz, void * object)
> Line 98 C++
>   qpid-protond.dll!pn_class_free(const pn_class_t * clazz, void * object)
> Line 120 C++
>   qpid-protond.dll!pn_free(void * object) Line 264 C++
>   qpid-protond.dll!pn_io_finalize(void * obj) Line 95 C++
>   qpid-protond.dll!pn_class_decref(const pn_class_t * clazz, void * object)
> Line 98 C++
>   qpid-protond.dll!pn_decref(void * object) Line 254 C++
>   qpid-protond.dll!pn_reactor_finalize(pn_reactor_t * reactor) Line 100 C++
>   qpid-protond.dll!pn_reactor_finalize_cast(void * object) Line 106 C++
>   qpid-protond.dll!pn_class_decref(const pn_class_t * clazz, void * object)
> Line 98 C++
>   qpid-protond.dll!pn_decref(void * object) Line 254 C++
>   qpid-proton-cppd.dll!proton::internal::pn_ptr_base::decref(void * p) Line
> 32 C++
>
> qpid-proton-cppd.dll!proton::internal::pn_ptr<pn_reactor_t>::~pn_ptr<pn_reactor_t>()
> Line 55 C++
>   [External Code]
>   qpid-proton-cppd.dll!proton::container_impl::~container_impl() Line 160
> C++
>   [External Code]
>   ssl.exe!hello_world_direct::on_transport_error(proton::transport & t)
> Line 134 C++
>
> qpid-proton-cppd.dll!proton::messaging_adapter::on_transport_closed(proton::proton_event
> & pe) Line 303 C++
>
> qpid-proton-cppd.dll!proton::proton_event::dispatch(proton::proton_handler
> & handler) Line 74 C++
>   qpid-proton-cppd.dll!proton::handler_context::dispatch(pn_handler_t *
> c_handler, pn_event_t * c_event, pn_event_type_t __formal) Line 74 C++
>   qpid-protond.dll!pn_handler_dispatch(pn_handler_t * handler, pn_event_t *
> event, pn_event_type_t type) Line 104 C++
>   qpid-protond.dll!pn_reactor_process(pn_reactor_t * reactor) Line 405 C++
>   qpid-protond.dll!pn_reactor_run(pn_reactor_t * reactor) Line 481 C++
>   qpid-proton-cppd.dll!proton::reactor::run() Line 38 C++
>   qpid-proton-cppd.dll!proton::container_impl::run() Line 352 C++
>   ssl.exe!proton::container_ref<std::auto_ptr<proton::container> >::run()
> Line 284 C++
>   ssl.exe!main(int argc, char * * argv) Line 173 C++
>   [External Code]
>
>
> Regards,
>
> Adel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org

Reply via email to