[nanomsg] NNG DLL not reentrant, not thread safe

  • From: Michael Powell <mwpowellhtx@xxxxxxxxx>
  • To: "nanomsg@xxxxxxxxxxxxx" <nanomsg@xxxxxxxxxxxxx>
  • Date: Mon, 6 Nov 2017 14:49:05 -0500

Fellow Travelers,

At the moment I have a strong suspicion that NNG threaded DLL
integration does not work. It is interesting that the code can be
packaged that way, but running in a threaded environment is a
non-starter. I've documented this fact at length in issues 151, 153,
and to some extent 150.

https://github.com/nanomsg/nng/issues/151
https://github.com/nanomsg/nng/issues/153
https://github.com/nanomsg/nng/issues/150

This is not a "C test case issue", when I've demonstrated that the C
calling conventions work very well as long as test fixtures are run
individually. Therefore, the C calling conventions into the DLL are my
starting point, and not "the C code".

However, when multiple test cases are running concurrently, each in a
different thread, none of them work. It doesn't matter what
protocol/transport is in play; I've tried homogeneous as well as
heterogeneous combinations.

The only error message I receive is a Visual Studio 2015 Test Runner error:

Logs from me test fixtures:

    BusTests.That_Bus1_delivers_message_to_both_Bus2_and_Bus3 [0:00.000] Aborted
Current process Id: 12004
Managed thread Id: 9 // <==============
Running protocol tests for address family 'IPv4'.
Testing using address 'tcp://127.0.0.1:10368'.
Given three 'Nanomsg2.Sharp.Protocols.Bus.LatestBusSocket' instances.

    PipelineTests.Load_balancing_works [0:00.000] Aborted
Current process Id: 12004
Managed thread Id: 11 // <==============
Running protocol tests for address family 'IPv4'.
Testing using address 'tcp://127.0.0.1:10304'.

And the runner:

2017.11.06 14:42:23.434   ERROR Process
C:\Users\Michael\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe:12004
exited with code '3'.

Versus a successful run individually:

    BusTests.That_Bus1_delivers_message_to_both_Bus2_and_Bus3 [0:00.272] Success
Current process Id: 10944
Managed thread Id: 9 // <==============
Running protocol tests for address family 'IPv4'.
Testing using address 'tcp://127.0.0.1:10368'.
Given three 'Nanomsg2.Sharp.Protocols.Bus.LatestBusSocket' instances.
  And messages can be delivered.
    And receive times out.
    And Bus1 delivers message to both Bus2 and Bus3.

    PipelineTests.Load_balancing_works [0:00.406] Success
Current process Id: 1576
Managed thread Id: 9 // <==============
Running protocol tests for address family 'IPv4'.
Testing using address 'tcp://127.0.0.1:10304'.

Cheers,

Michael Powell

Other related posts: