From: Matthias Kruk Date: Wed, 1 Dec 2021 09:40:28 +0000 (+0900) Subject: include/ipc: Use the endpoint name as name for pubsub subscriptions X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=4c2d817f9568881b9f53acdab909c328646e6097;p=toolbox include/ipc: Use the endpoint name as name for pubsub subscriptions When subscribing to a pubsub channel, a name constructed from the hostname and pid is used for the subscription name. When multiple processes subscribe to the same topic using the same endpoint, this causes the endpoint to be subscribed multiple times, and multiple messages to be received by the endpoint, when it should only receive one message (this usage is intended for load-balancing over pubsub channels). This commit modifies the ipc module so that the name of the endpoint is used for the subscription name, preventing an endpoint from being subscribed multiple times to the same topic. --- diff --git a/include/ipc.sh b/include/ipc.sh index c0b99bc..642f6bc 100644 --- a/include/ipc.sh +++ b/include/ipc.sh @@ -25,7 +25,6 @@ __init() { declare -gxr __ipc_public="$__ipc_root/pub" declare -gxr __ipc_private="$__ipc_root/priv/$USER" declare -gxr __ipc_group="toolbox_ipc" - declare -gxr __ipc_self="$HOSTNAME.$$" declare -gxr __ipc_pubsub_root="$__ipc_root/pubsub" declare -gxir __ipc_version=1 @@ -515,7 +514,7 @@ ipc_endpoint_close() { fi while read -r subscription; do - if ! rm "$subscription/$__ipc_self"; then + if ! rm "$subscription/${name//\//_}"; then log_error "Could unsubscribe $name from $subscription" fi done < <(find "$endpoint/subscriptions") @@ -647,15 +646,17 @@ _ipc_endpoint_topic_subscribe() { local topic="$2" local topicdir + local subscription topicdir="$__ipc_pubsub_root/$topic" + subscription="$topicdir/${endpoint//\//_}" - if ! ln -sf "$endpoint" "$topicdir/$__ipc_self"; then + if ! ln -sf "$endpoint" "$subscription"; then return 1 fi if ! ln -sfn "$topicdir" "$__ipc_root/$endpoint/subscriptions/$topic"; then - rm -f "$topicdir/$__ipc_self" + rm -f "$subscription" return 1 fi