From 198d04d3ef7038f5b3619d82f160eb8ed068c6a9 Mon Sep 17 00:00:00 2001 From: Bill Torpey Date: Thu, 1 Jun 2023 10:37:46 -0400 Subject: [PATCH 1/4] fix leak --- src/bridge.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bridge.c b/src/bridge.c index ebb6307..5dcc05b 100755 --- a/src/bridge.c +++ b/src/bridge.c @@ -149,7 +149,8 @@ zmqBridge_close(mamaBridge bridgeImpl) /* The timer thread expects us to be responsible for terminating it */ wthread_join(timerThread, NULL); } - mamaBridgeImpl_setClosure(bridgeImpl, NULL); + mamaBridgeImpl_setClosure(bridgeImpl, NULL); + free(closure); /* Destroy once queue has been emptied */ mama_getDefaultEventQueue(bridgeImpl, &defaultEventQueue); From b07efa096168c83cabca95dc3ef5fef2f5314524 Mon Sep 17 00:00:00 2001 From: Bill Torpey Date: Tue, 25 Jul 2023 15:53:23 -0400 Subject: [PATCH 2/4] - update log msgs text, severity --- src/transport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transport.c b/src/transport.c index ea07c0a..8778ac8 100755 --- a/src/transport.c +++ b/src/transport.c @@ -702,7 +702,7 @@ mama_status zmqBridgeMamaTransportImpl_dispatchNamingMsg(zmqTransportBridge* imp wlock_unlock(impl->mZmqDataPub.mLock); #endif - MAMA_LOG(MAMA_LOG_LEVEL_NORMAL, "Disconnecting data sockets from publisher:%s", pMsg->mEndPointAddr); + MAMA_LOG(MAMA_LOG_LEVEL_NORMAL, "Disconnected data sockets from publisher:%s", pMsg->mEndPointAddr); } else if (pMsg->mType == 'W') { // welcome msg - naming subscriber is connected @@ -1005,7 +1005,7 @@ void MAMACALLTYPE zmqBridgeMamaTransportImpl_wcCallback(mamaQueue queue, void* findClosure.mSubscription = NULL; list_for_each(tmsg->mTransport->mWcEndpoints, (wListCallback) zmqBridgeMamaTransportImpl_findWildcard, &findClosure); if (findClosure.mSubscription == NULL) { - MAMA_LOG(MAMA_LOG_LEVEL_ERROR, "No endpoint found for topic %s with id %s", subject, tmsg->mEndpointIdentifier); + MAMA_LOG(MAMA_LOG_LEVEL_WARN, "No endpoint found for topic %s with id %s", subject, tmsg->mEndpointIdentifier); goto exit; } @@ -1205,7 +1205,7 @@ mama_status zmqBridgeMamaTransportImpl_disconnectSocket(zmqSocket* socket, const int rc = zmq_disconnect(socket->mSocket, uri); if (0 != rc) { - MAMA_LOG(MAMA_LOG_LEVEL_ERROR, "zmq_disconnect(%p, %s) failed: %d(%s)", socket->mSocket, uri, zmq_errno(), zmq_strerror(errno)); + MAMA_LOG(MAMA_LOG_LEVEL_WARN, "zmq_disconnect(%p, %s) failed: %d(%s)", socket->mSocket, uri, zmq_errno(), zmq_strerror(errno)); status = MAMA_STATUS_PLATFORM; } From 4eecc9f231fa4680bdf2e4768afeb83f8bc9f045 Mon Sep 17 00:00:00 2001 From: Bill Torpey Date: Tue, 25 Jul 2023 15:54:29 -0400 Subject: [PATCH 3/4] update examples, scripts, docs --- CMakeLists.txt | 1 + doc/pol.pl.md | 39 +++++++++++++++++++++++++------------ examples/CMakeLists.txt | 4 ++++ examples/leak.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ scripts/CMakeLists.txt | 3 +++ scripts/pol.pl | 36 ++++++++++++++++++++++++++++++++-- 6 files changed, 112 insertions(+), 14 deletions(-) create mode 100644 examples/leak.cpp create mode 100644 scripts/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 889d9df..6c7bd5b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,3 +54,4 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNFLAGS}") add_subdirectory(src) add_subdirectory(examples) +add_subdirectory(scripts) diff --git a/doc/pol.pl.md b/doc/pol.pl.md index 00758c8..0a875b9 100644 --- a/doc/pol.pl.md +++ b/doc/pol.pl.md @@ -6,21 +6,36 @@ It processes messages for the OZ "dataSub" and "namingPub" sockets, as these are ## Usage -`pol.pl ` +`pol.pl -g '' ` -Note that the log file must contain naming messages (`log_level_naming` in mama.properties) to get the process's name and PID. +Parameter | Meaning +----------| ------- +-g | Specifies a "grep" string that is used to filter the output. You can specify any valid Perl regex for grep-string (see example below). + +The output of the command is in tab-separated format, and can easily be imported into most spreadsheet programs. + +### Notes + +1. The log file must contain naming messages (`log_level_naming` in mama.properties) to get the process's name and PID. +2. Only the first CONNECT REQ from a particular endpoint is displayed -- subsequent CONNECT REQ messages are discarded. ## Example -Below is an example of importing the tab-separated file into a spreadsheet program. + +``` +$ pol.pl -g 'tpsdaemon|tpsworker' abim3.log +``` Time | Event | Host | Port | Prog | PID | fd ---- | ----- | ----- | ---- | ---- | --- | --- -11/17 10:34:08.491951|CONNECTED|bt-brixu|40895|nsd|157751|30 -11/17 10:34:08.492716|HANDSHAKE_SUCCEEDED|bt-brixu|40895|nsd|157751|30 -11/17 10:34:08.495518|CONNECTED|bt-brixu|34161|tpsdaemon|157776|32 -11/17 10:34:08.496640|CONNECTED|bt-brixu|43813|svr_state_mon|157774|34 -11/17 10:34:08.496754|CONNECTED|bt-brixu|39039|check_status|157778|28 -11/17 10:34:08.496882|HANDSHAKE_SUCCEEDED|bt-brixu|34161|tpsdaemon|157776|32 -11/17 10:34:08.497212|HANDSHAKE_SUCCEEDED|bt-brixu|43813|svr_state_mon|157774|34 -11/17 10:34:08.497612|HANDSHAKE_SUCCEEDED|bt-brixu|39039|check_status|157778|28 -11/17 10:34:10.666831|DISCONNECTED|bt-brixu|39039|check_status|157778|28 +6/13 16:07:13.200262|WELCOME|nsb12|40953|nsd|12773|0 +6/13 16:07:13.200646|CONNECTED|nsb12|40953|nsd|12773|39 +6/13 16:07:13.201104|HANDSHAKE_SUCCEEDED|nsb12|40953|nsd|12773|39 +6/13 16:07:13.206905|CONNECT REQ|nsb11|36375|tpsdaemon|16384|0 +6/13 16:07:13.207090|CONNECT REQ|nsb12|39195|tpsdaemon|18893|0 +6/13 16:07:13.207611|CONNECT REQ|nsb12|43814|tpsdaemon|12334|0 +6/13 16:07:13.209573|CONNECTED|nsb12|39195|tpsdaemon|18893|52 +6/13 16:07:13.209682|CONNECTED|nsb11|36375|tpsdaemon|16384|51 +6/13 16:07:13.232949|HANDSHAKE_SUCCEEDED|nsb11|43735|tpsworker|16623|81 +6/13 16:07:13.233025|HANDSHAKE_SUCCEEDED|nsb11|42554|tpsworker|16884|97 +6/13 16:07:13.233087|HANDSHAKE_SUCCEEDED|nsb11|37988|tpsworker|20351|93 +6/13 16:07:13.236395|HANDSHAKE_SUCCEEDED|nsb11|36375|tpsdaemon|16384|51 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f4dc214..9affb04 100755 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -42,3 +42,7 @@ install(TARGETS timer DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) add_executable(timer2 timer2.cpp) target_link_libraries(timer2 ozimpl mama) install(TARGETS timer2 DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) + +add_executable(leak leak.cpp) +target_link_libraries(leak ozimpl mama) +install(TARGETS leak DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/examples/leak.cpp b/examples/leak.cpp new file mode 100644 index 0000000..fc49047 --- /dev/null +++ b/examples/leak.cpp @@ -0,0 +1,43 @@ +// just to verify that asan/lsan are working properly + +#include +#include +using namespace std; + +#include + +#include "ozimpl.h" +using namespace oz; + +class myTimerEvents : public timerEvents +{ + virtual void MAMACALLTYPE onTimer() override + { + static int i = 0; + fprintf(stderr, "timer=%d\n", ++i); + } +}; + + +int main(int argc, char** argv) +{ + cmdLine cli(argc, argv); + + auto conn = createConnection(cli.getMw(), cli.getPayload(), cli.getTportSub()); + TRY_MAMA_FUNC(conn->start()); + + auto sess = conn->createSession(); + TRY_MAMA_FUNC(sess->start()); + + myTimerEvents timerEvents; + auto pTimer = sess->createTimer(0.5, &timerEvents).release(); + TRY_MAMA_FUNC(pTimer->start()); + + sleep(5); + + pTimer->destroy(); + + void* leak = malloc(512); + + return 0; +} diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt new file mode 100644 index 0000000..bb0d276 --- /dev/null +++ b/scripts/CMakeLists.txt @@ -0,0 +1,3 @@ +file(GLOB perl "*.pl") +install(PROGRAMS ${perl} DESTINATION scripts) + diff --git a/scripts/pol.pl b/scripts/pol.pl index 6c7ed6e..b1741cc 100755 --- a/scripts/pol.pl +++ b/scripts/pol.pl @@ -3,6 +3,14 @@ # parse OZ logs # +# get params +use Getopt::Long qw(:config pass_through); + +# matching +my $grep; +GetOptions( 'g|grep=s' => \$grep ); + + use Class::Struct; struct Peer => { prog => '$', @@ -33,6 +41,12 @@ sub getPeer { return $peer, $exists; } +sub printg { + my $format = shift; + my $line = sprintf $format, @_; + print $line if (!defined $grep || (($line =~ $grep) || ($line =~ "nsd"))); +} + # take filename arg on cmd line, or read from stdin local *INFILE; if ( defined( $ARGV[0] ) ) { @@ -78,7 +92,22 @@ sub getPeer { } next if $#fields eq 0; if ($msg eq "zmqBridgeMamaTransportImpl_dispatchNamingMsg" ) { + my $sockType = "namingSub"; if ( ($type =~ "Received endpoint msg") || ($type =~ "Published endpoint msg") ) { + my $msgtype = ((split('=', $fields[0]))[1]); + my $event; + if ($msgtype eq "W") { + $event = "WELCOME"; + } + elsif ($msgtype eq "C") { + $event = "CONNECT REQ"; + } + elsif ($msgtype eq "D") { + $event = "DISCONNECT REQ"; + } + else { + $event = "UNKOWN"; + } my $endpoint = ((split('=', $fields[6]))[1]); my ($peer, $exists) = getPeer($endpoint); $peer->prog((split('=', $fields[1]))[1]); @@ -91,6 +120,9 @@ sub getPeer { if (!exists($hosts{$peer->addr()})) { $hosts{$peer->addr()} = $peer->host(); } + if (($msgtype ne "C") || !$exists) { + printg("%s\t%s\t%s\t%d\t%s\t%d\t%d\n", $timestamp, $event, $peer->host(), $peer->port(), $peer->prog(), $peer->pid(), $peer->fd()); + } } } elsif ($msg eq "zmqBridgeMamaTransportImpl_monitorEvent" ) { @@ -110,7 +142,7 @@ sub getPeer { my ($peer, $exists) = getPeer($endpoint); my $fd = (split(':', $fields[3]))[1]; $peer->fd($fd) if $fd != 0; - printf("%s\t%s\t%s\t%d\t%s\t%d\t%d\n", $timestamp, $event, $peer->host(), $peer->port(), $peer->prog(), $peer->pid(), $peer->fd()); + printg("%s\t%s\t%s\t%d\t%s\t%d\t%d\n", $timestamp, $event, $peer->host(), $peer->port(), $peer->prog(), $peer->pid(), $peer->fd()); } } elsif ($msg eq "zmqBridgeMamaTransportImpl_monitorEvent_v2" ) { @@ -130,7 +162,7 @@ sub getPeer { my ($peer, $exists) = getPeer($endpoint); my $fd = (split(':', $fields[2]))[1]; $peer->fd($fd) if $fd != 0; - printf("%s\t%s\t%s\t%d\t%s\t%d\t%d\n", $timestamp, $event, $peer->host(), $peer->port(), $peer->prog(), $peer->pid(), $peer->fd()); + printg("%s\t%s\t%s\t%d\t%s\t%d\t%d\n", $timestamp, $event, $peer->host(), $peer->port(), $peer->prog(), $peer->pid(), $peer->fd()); } } } From 875659f4921392e55e8e1ba0e3dd1678a058fe8a Mon Sep 17 00:00:00 2001 From: Bill Torpey Date: Thu, 19 Oct 2023 07:46:14 -0400 Subject: [PATCH 4/4] [BUS-2289] - revert 08ee0376c94726b7eb2087a9c9573a6b909a8561 --- src/subscription.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/subscription.c b/src/subscription.c index 1f5bf93..2fd6e68 100755 --- a/src/subscription.c +++ b/src/subscription.c @@ -113,10 +113,16 @@ mama_status zmqBridgeMamaSubscription_createWildCard(subscriptionBridge* subscri if (prefix[0] == '^') { ++prefix; // skip beginning anchor } - char* regexPos = strpbrk(prefix, "[^/]+.*"); // find wildcard regex? + char* regexPos = strstr(prefix, "[^/]+"); // find wildcard regex? if (regexPos != NULL) { *regexPos = '\0'; // overwrite with null } + else { + int l = strlen(prefix); + if (strcmp(&prefix[l-3], "/.*") == 0) { // find trailing "super" wildcard? + prefix[l-2] = '\0'; // overwrite with null + } + } MAMA_LOG(MAMA_LOG_LEVEL_FINE, "source=%s,prefix=%s", source, prefix); // create regex to match against