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

Incorrect out-of-memory errors being reported #2627

Open
dirkfeytons opened this issue Sep 5, 2022 · 0 comments
Open

Incorrect out-of-memory errors being reported #2627

dirkfeytons opened this issue Sep 5, 2022 · 0 comments

Comments

@dirkfeytons
Copy link

Similar to #2525 I encountered a situation where incorrectly an out-of-memory was reported: a client connected to the Mosquitto broker, published a message and disconnected without properly waiting for the puback. The broker would then log a message saying the client disconnected due to out-of-memory while the correct error is "broken pipe".

I can fix this with a patch like the following (against 2.0.15):

diff --git a/src/handle_publish.c b/src/handle_publish.c
index 111f0316..8736812d 100644
--- a/src/handle_publish.c
+++ b/src/handle_publish.c
@@ -332,9 +332,9 @@ int handle__publish(struct mosquitto *context)
                        rc2 = sub__messages_queue(context->id, stored->topic, stored->qos, stored->retain, &stored);
                        /* stored may now be free, so don't refer to it */
                        if(rc2 == MOSQ_ERR_SUCCESS || context->protocol != mosq_p_mqtt5){
-                               if(send__puback(context, mid, 0, NULL)) rc = 1;
+                               rc = send__puback(context, mid, 0, NULL);
                        }else if(rc2 == MOSQ_ERR_NO_SUBSCRIBERS){
-                               if(send__puback(context, mid, MQTT_RC_NO_MATCHING_SUBSCRIBERS, NULL)) rc = 1;
+                               rc = send__puback(context, mid, MQTT_RC_NO_MATCHING_SUBSCRIBERS, NULL);
                        }else{
                                rc = rc2;
                        }

While this seems to fix my particular scenario with minimal changes I think more improvements can be done: it looks to me like rc2 can be eliminated (in the above piece of code at least). And if I look further in this file I think there are other cases where rc = 1 is done instead of propagating the return value of a helper function.
Grepping the code for rc = 1; reveals some other places that seem to me to warrant further investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant