Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clients disconnected on SIGHUP #1521

Closed
ckrey opened this issue Nov 30, 2019 · 6 comments
Closed

Clients disconnected on SIGHUP #1521

ckrey opened this issue Nov 30, 2019 · 6 comments

Comments

@ckrey
Copy link

ckrey commented Nov 30, 2019

I found a way to reproduce the problem reported in #1494:

@ckrey
Copy link
Author

ckrey commented Nov 30, 2019

Minimal mosquitto.conf:

pid_file /tmp/mosquitto.pid
persistence true
persistence_location /tmp/
allow_anonymous false
log_dest file /tmp/mosquitto.log
autosave_interval 10
persistent_client_expiration 1w
connection_messages true
log_type all
log_timestamp true

  1. run mosquitto with that config
  2. run mosquitto_sub -u user1 -P password1 -i client1 -c -t abc -v
  3. abort mosquitto_sub
  4. stop mosquitto
  5. restart mosquitto with that config
  6. now send mosquitto a SIGHUP signal

mosquitto.log`:

...
1575150018: Reloading config.
1575150018: Client client1 disconnected.
...

The code triggering the disconnect is in security_default.c/mosquitto_security_apply_default
context__disconnect then calls session_expiry__add.

The result is:
If there are inactive clients and mosquitto is once restarted, the daily SIGHUPs used for log rotation
cause the session expiry mechanism to be reset every day.

Probably context__disconnect should return if the context is already disconnected.

@ckrey
Copy link
Author

ckrey commented Nov 30, 2019

P.S. to find the problem, I extended db_dump.c a bit:

diff --git a/src/db_dump/db_dump.c b/src/db_dump/db_dump.c
index 45eb80a..4605d6f 100644
--- a/src/db_dump/db_dump.c
+++ b/src/db_dump/db_dump.c
@@ -45,6 +45,8 @@ struct client_data
        int subscription_size;
        int messages;
        long message_size;
+       int64_t session_expiry_time;
+       uint32_t session_expiry_interval;
 };

 struct msg_store_chunk
@@ -167,6 +169,8 @@ static int dump__client_chunk_process(struct mosquitto_db *db, FILE *db_fd, uint
                        return 1;
                }
                cc->id = strdup(chunk.client_id);
+               cc->session_expiry_time = chunk.F.session_expiry_time;
+               cc->session_expiry_interval = chunk.F.session_expiry_interval;
                HASH_ADD_KEYPTR(hh_id, clients_by_id, cc->id, strlen(cc->id), cc);
        }

@@ -467,8 +471,15 @@ int main(int argc, char *argv[])

        if(client_stats){
                HASH_ITER(hh_id, clients_by_id, cc, cc_tmp){
-                       printf("SC: %d SS: %d MC: %d MS: %ld   ", cc->subscriptions, cc->subscription_size, cc->messages, cc->message_size);
-                       printf("%s\n", cc->id);
+                       printf("SC: %d SS: %d MC: %d MS: %ld SET: %" PRIu64 " SEI: %u ID: %s\n",
+                                       cc->subscriptions,
+                                       cc->subscription_size,
+                                       cc->messages,
+                                       cc->message_size,
+                                       cc->session_expiry_time,
+                                       cc->session_expiry_interval,
+                                       cc->id
+                                       );
                        free(cc->id);
                }
        }

@karlp
Copy link
Contributor

karlp commented Dec 2, 2019

Is your "minimial config" complete? do you meant to have no passwords, is that the edge case you're trying to hit?

@ckrey
Copy link
Author

ckrey commented Dec 2, 2019

yes it is complete, the trigger is the allow_anonymous false

it doesn't matter if the user/password combinations are actually valid.
Thus we don't need an actual mosquitto.acl file, although it wouldn't change the result

@karlp
Copy link
Contributor

karlp commented Dec 2, 2019

So the users/passwords provided in your mosquitto_sub line are arbitrary then?

@ckrey
Copy link
Author

ckrey commented Dec 2, 2019

yes, just to be non-anonymous

FranciscoKnebel pushed a commit to Open-Digital-Twin/mosquitto that referenced this issue Jul 30, 2020
This prevents the session expiry being extended on SIGHUP.

Closes eclipse#1521. Thanks to Christoph Krey.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants