Skip to content

Instantly share code, notes, and snippets.

@cxreg
Created October 27, 2016 19:01
Show Gist options
  • Save cxreg/806f2e51b8cce4a67e362d3dce86cfbc to your computer and use it in GitHub Desktop.
Save cxreg/806f2e51b8cce4a67e362d3dce86cfbc to your computer and use it in GitHub Desktop.
zmq set_metadata crash repro
daveo@abraxas:~/zmq-crash-repro$ more server.c client.c
::::::::::::::
server.c
::::::::::::::
// invoked as valgrind ./server
#include <zmq.h>
void main(void) {
void *ctx = zmq_ctx_new();
void *socket = zmq_socket(ctx, ZMQ_XPUB);
int one = 1;
char *secret_key = "2).NRO5d[JbEFli7F@hdvE1(Fv?B6iIAn>NcLLDx";
zmq_setsockopt(socket, ZMQ_CURVE_SERVER, &one, sizeof(one));
zmq_setsockopt(socket, ZMQ_CURVE_SECRETKEY, secret_key, 40);
zmq_bind(socket, "tcp://*:9999");
while (1) {
char buf[256];
zmq_recv(socket, buf, 256, 0);
//if (buf[0] == 1) fprintf(stderr, "got %s\n", buf + 1);
}
}
::::::::::::::
client.c
::::::::::::::
// run as: while ./client; do :; done
#include <zmq.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
// Magic constant, needs to be sufficient time to get the server processing
// the subscription but then exit before it's done. Curve is used only
// because it adds time and cost to the equation, and probably is not a
// functioning part of error. This value was narrowed down based on the
// behavior of my computer and with the server running in valgrind
#define DELAY 28000
void main(void) {
void *ctx = zmq_ctx_new();
void *socket = zmq_socket(ctx, ZMQ_SUB);
char *sub = "subscription";
char public_key[41], private_key[41];
char *server_key = "^kvy<i^qI<r{=ZDrfK4K<#NtqY+zaH:ksm/YGE6I";
zmq_curve_keypair(public_key, private_key);
zmq_setsockopt(socket, ZMQ_CURVE_SERVERKEY, server_key, 40);
zmq_setsockopt(socket, ZMQ_CURVE_PUBLICKEY, public_key, 40);
zmq_setsockopt(socket, ZMQ_CURVE_SECRETKEY, private_key, 40);
zmq_connect(socket, "tcp://localhost:9999");
zmq_setsockopt(socket, ZMQ_SUBSCRIBE, sub, strlen(sub));
usleep(rand() % DELAY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment