]> git.corax.cc Git - toolbox/commitdiff
include/ipc: Use the endpoint name as name for pubsub subscriptions
authorMatthias Kruk <m@m10k.eu>
Wed, 1 Dec 2021 09:40:28 +0000 (18:40 +0900)
committerMatthias Kruk <m@m10k.eu>
Wed, 1 Dec 2021 09:40:28 +0000 (18:40 +0900)
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.

include/ipc.sh

index c0b99bc1f792a2471f414c46974cebab97b68c2c..642f6bcde4c7027f498b364ec289f1c1a9202a9b 100644 (file)
@@ -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