Skip to content

broker: EVT_CONNECT from all listeners called upon connection #3534

@ymorin-orange

Description

@ymorin-orange

What hapens:

Given a configuration with multiple listeners, with each listener loading a plugin that registers an EVT_CONNECT callback, when a client connects to a listener, then the EVT_CONNECT callback for all plugins of all listeners are called.


How to reproduce:

  1. Build the plugins/examples/connection-state/ plugin
  2. start a mosquitto broker (with the -v option) with this configuration:
    listener 1883 0.0.0.0
    listener_allow_anonymous true
    
    listener 1884 0.0.0.0
    listener_allow_anonymous true
    plugin /usr/lib/mosquitto_connection_state.so
    
    listener 1885 0.0.0.0
    listener_allow_anonymous true
    plugin /usr/lib/mosquitto_connection_state.so
    
    listener 1886 0.0.0.0
    listener_allow_anonymous true
    plugin /usr/lib/mosquitto_connection_state.so
    plugin /usr/lib/mosquitto_connection_state.so  # Loaded twice, not an error!
    
    • notice that the broker reports loading the plugin for each listener:
      1772517942: Loading plugin: /usr/lib/mosq_test.so
      1772517942: Plugin connection-state has registered to receive 'connect' events.
      1772517942: Plugin connection-state has registered to receive 'disconnect' events.
      1772517942: Plugin connection-state version 1.0 loaded.
      1772517942: Loading plugin: /usr/lib/mosq_test.so
      1772517942: Plugin connection-state has registered to receive 'connect' events.
      1772517942: Plugin connection-state has registered to receive 'disconnect' events.
      1772517942: Plugin connection-state version 1.0 loaded.
      1772517942: Loading plugin: /usr/lib/mosq_test.so
      1772517942: Plugin connection-state has registered to receive 'connect' events.
      1772517942: Plugin connection-state has registered to receive 'disconnect' events.
      1772517942: Plugin connection-state version 1.0 loaded.
      1772517942: Loading plugin: /usr/lib/mosq_test.so
      1772517942: Plugin connection-state has registered to receive 'connect' events.
      1772517942: Plugin connection-state has registered to receive 'disconnect' events.
      1772517942: Plugin connection-state version 1.0 loaded.
      1772517942: Opening ipv4 listen socket on port 1883.
      1772517942: Opening ipv4 listen socket on port 1884.
      1772517942: Opening ipv4 listen socket on port 1885.
      1772517942: Opening ipv4 listen socket on port 1886.
      
  3. once the broker is ready to serve, spawn a subscriber on port 1883, that listens to the connection topics: mosquitto_sub -t '$SYS/broker/connection/client/#' -i foo -F '%t %p'
    • notice that there is a first trace for that client, although it connects on a listener that has not loaded the plugin:
      $SYS/broker/connection/client/foo/state 1
      
    • notice that the broker sends a PUBLISH:
      1772517957: New connection from 10.0.2.100:45670 on port 1883.
      1772517957: New client connected from 10.0.2.100:45670 as foo (p4, c1, k60).
      1772517957: No will message specified.
      1772517957: Sending CONNACK to foo (0, 0)
      1772517957: Received SUBSCRIBE from foo
      1772517957:     $SYS/broker/connection/client/# (QoS 0)
      1772517957: foo 0 $SYS/broker/connection/client/#
      1772517957: Sending SUBACK to foo
      1772517957: Sending PUBLISH to foo (d0, q0, r1, m0, '$SYS/broker/connection/client/foo/state', ... (1 bytes))
      
  4. run a second MQTT client (it can be whatever, let's just use mosquitto_sub again for the sake of the test): mosquitto_sub -t '#' -i bar
    • notice that there are four events reported by the first subscriber, one per plugin loaded, although this second client connects on a listener that has not loaded the plugin:
      $SYS/broker/connection/client/bar/state 1
      $SYS/broker/connection/client/bar/state 1
      $SYS/broker/connection/client/bar/state 1
      $SYS/broker/connection/client/bar/state 1
      
    • notice also that the broker reports four PUBLISH:
      1772518035: New connection from 10.0.2.100:34908 on port 1883.
      1772518035: New client connected from 10.0.2.100:34908 as bar (p4, c1, k60).
      1772518035: No will message specified.
      1772518035: Sending CONNACK to bar (0, 0)
      1772518035: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518035: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518035: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518035: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      
  5. terminate that second client with Ctrl-C:
    • notice that there are four events reported by the first subscriber, one per plugin loaded, although this second client connected on a listener that has not loaded the plugin:
      $SYS/broker/connection/client/bar/state 0
      $SYS/broker/connection/client/bar/state 0
      $SYS/broker/connection/client/bar/state 0
      $SYS/broker/connection/client/bar/state 0
      
    • notice also that the broker reports four PUBLISH:
      1772518039: Received DISCONNECT from bar
      1772518039: Client bar [10.0.2.100:34908] disconnected.
      1772518039: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518039: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518039: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518039: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      
  6. run a third MQTT client (it can be whatever, let's just use mosquitto_sub again for the sake of the test) on a port with the plugin loaded: mosquitto_sub -t '#' -i bar -p 1884
    • notice that there are four events reported by the first subscriber, one per plugin loaded, although this third client connects on a listener that has loaded the plugin only once:
      $SYS/broker/connection/client/bar/state 1
      $SYS/broker/connection/client/bar/state 1
      $SYS/broker/connection/client/bar/state 1
      $SYS/broker/connection/client/bar/state 1
      
    • notice also that the broker reports four PUBLISH:
      1772518048: New connection from 10.0.2.100:58406 on port 1883.
      1772518048: New client connected from 10.0.2.100:58406 as bar (p4, c1, k60).
      1772518048: No will message specified.
      1772518048: Sending CONNACK to bar (0, 0)
      1772518048: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518048: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518048: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518048: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      
  7. terminate that third client with Ctrl-C:
    • notice that there are four events reported by the first subscriber, one per plugin loaded:
      $SYS/broker/connection/client/bar/state 0
      $SYS/broker/connection/client/bar/state 0
      $SYS/broker/connection/client/bar/state 0
      $SYS/broker/connection/client/bar/state 0
      
    • notice also that the broker reports four PUBLISH:
      1772518052: Received DISCONNECT from bar
      1772518052: Client bar [10.0.2.100:58406] disconnected.
      1772518052: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518052: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518052: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      1772518052: Sending PUBLISH to foo (d0, q0, r0, m0, '$SYS/broker/connection/client/bar/state', ... (1 bytes))
      

Expected behaviour:

Only the EVT_CONNECT callbacks from the plugins loaded by the listener the client connects to, should be called, like all other callbacks behave.

Notice that EVT_DISCONNECT callbacks have the same issue as for EVT_CONNECT.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: AvailableNo one has claimed responsibility for resolving this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions