zeromq / cppzmq

Header-only C++ binding for libzmq
http://www.zeromq.org
MIT License
1.93k stars 757 forks source link

Assertion failed: socket_type >= 0 && socket_type < (int) names_count (src/mechanism.cpp:110) #588

Open renukamanavalan opened 1 year ago

renukamanavalan commented 1 year ago

[ Filed as issue #4487 in github zeromq/libzmq -- Extending to here too]

Issue description

Simple ZMQ model using ZMQ_CLIENT & ZMQ_SERVER fails with following assertion. Assertion failed: socket_type >= 0 && socket_type < (int) names_count (src/mechanism.cpp:110)

Code is pretty simple. Invoke it in client / server mode. Server: Creates sock, binds and sleep for an hour before exiting Client: Creates sock, connect & sleep

The assertion happens while the main thread is sleeping.

BTW, I saw it working for a while, before failing consistently.

Environment

# Minimal test code / Steps to reproduce the issue

include

include

include

include

include

include

const char *zmq_path = "tcp://127.0.0.1:5555";

int main(int argc, char *argv) { int opt; int run_server = 0; void zmq_ctx = NULL; void *zmq_sck = NULL; char buf[10];

while ((opt = getopt(argc, argv, "s")) != -1) {
    switch (opt) {
    case 's':
        run_server = 1;
        break;

    default: /* '?' */
        fprintf(stderr, "Usage: %s [-s]\n", argv[0]);
        exit(-1);
    }
}

zmq_ctx = zmq_ctx_new ();

if (run_server != 0) {
    zmq_sck = zmq_socket (zmq_ctx, ZMQ_SERVER);

    printf ("Binding to server %s\n", zmq_path);
    zmq_bind (zmq_sck, zmq_path);
    printf ("Bound to server %s\n", zmq_path);

}
else {
    zmq_sck = zmq_socket (zmq_ctx, ZMQ_CLIENT);

    printf ("connecting server %s\n", zmq_path);
    zmq_connect (zmq_sck, zmq_path);
    printf ("Connected to server %s\n", zmq_path);

}
printf("Sleeping\n");
sleep(3600);
printf("Closing socket...\n");
zmq_close (zmq_sck);
printf("Destroy context ...\n");
zmq_ctx_destroy (zmq_ctx);

}


# What's the actual result? (include assertion message & call stack if applicable)
As Server:
NOTE: Assertion is while sleeping

localadmin@remanava-dev-1:~/tools/zmq/c/client_server$ ./t -s Binding to server tcp://127.0.0.1:5555 Bound to server tcp://127.0.0.1:5555 Sleeping Assertion failed: socket_type >= 0 && socket_type < (int) names_count (src/mechanism.cpp:110) Aborted (core dumped) localadmin@remanava-dev-1:~/tools/zmq/c/client_server$


As client:
NOTE: Assertion is while sleeping - implying during async connect 

localadmin@remanava-dev-1:~/tools/zmq/c/client_server$ ./t connecting server tcp://127.0.0.1:5555 Connected to server tcp://127.0.0.1:5555 Sleeping Assertion failed: socket_type >= 0 && socket_type < (int) names_count (src/mechanism.cpp:110) Aborted (core dumped) localadmin@remanava-dev-1:~/tools/zmq/c/client_server$



# What's the expected result?
No assertion.
Connection to succeed.
gummif commented 1 year ago

4.2.5 is 5 years old. You should probably try again with a more recent version.

renukamanavalan commented 1 year ago

Thanks gummif. I tried "apt update"; "sudo apt remove libzmq3-dev" and tried install "sudo apt-get install libzmq5-dev" Still I end up with 4.2.5 only.

How could I force upgrade to latest?

localadmin@remanava-dev-1:~/source/fork/Device-Health/first-cut/src/lib$ sudo apt list --installed | grep -i zmq

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libzmq3-dev/bionic-updates,bionic-security,now 4.2.5-1ubuntu0.2 amd64 [installed]
libzmq5/bionic-updates,bionic-security,now 4.2.5-1ubuntu0.2 amd64 [installed]
localadmin@remanava-dev-1:~/source/fork/Device-Health/first-cut/src/lib$ sudo apt remove libzmq3-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-azure-5.4-cloud-tools-5.4.0-1091 linux-azure-5.4-headers-5.4.0-1091 linux-azure-5.4-tools-5.4.0-1091
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  libzmq3-dev
0 upgraded, 0 newly installed, 1 to remove and 60 not upgraded.
After this operation, 2227 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 245924 files and directories currently installed.)
Removing libzmq3-dev:amd64 (4.2.5-1ubuntu0.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
localadmin@remanava-dev-1:~/source/fork/Device-Health/first-cut/src/lib$ sudo apt-get install libzmq5-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libzmq3-dev' instead of 'libzmq5-dev'
The following packages were automatically installed and are no longer required:
  linux-azure-5.4-cloud-tools-5.4.0-1091 linux-azure-5.4-headers-5.4.0-1091 linux-azure-5.4-tools-5.4.0-1091
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  libzmq3-dev
0 upgraded, 1 newly installed, 0 to remove and 60 not upgraded.
Need to get 400 kB of archives.
After this operation, 2227 kB of additional disk space will be used.
Get:1 http://azure.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 libzmq3-dev amd64 4.2.5-1ubuntu0.2 [400 kB]
Fetched 400 kB in 0s (17.8 MB/s)    
Selecting previously unselected package libzmq3-dev:amd64.
(Reading database ... 245851 files and directories currently installed.)
Preparing to unpack .../libzmq3-dev_4.2.5-1ubuntu0.2_amd64.deb ...
Unpacking libzmq3-dev:amd64 (4.2.5-1ubuntu0.2) ...
Setting up libzmq3-dev:amd64 (4.2.5-1ubuntu0.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
localadmin@remanava-dev-1:~/source/fork/Device-Health/first-cut/src/lib$ sudo apt list --installed | grep -i zmq

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libzmq3-dev/bionic-updates,bionic-security,now 4.2.5-1ubuntu0.2 amd64 [installed]
libzmq5/bionic-updates,bionic-security,now 4.2.5-1ubuntu0.2 amd64 [installed]
localadmin@remanava-dev-1:~/source/fork/Device-Health/first-cut/src/lib$ 
gummif commented 1 year ago

I guess build from source, use a package manager like conan or use docker with a new ubuntu are options.