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

mosquitto_loop return MOSQ_ERR_INVAL #1299

Open
xieyuyang opened this issue May 30, 2019 · 8 comments
Open

mosquitto_loop return MOSQ_ERR_INVAL #1299

xieyuyang opened this issue May 30, 2019 · 8 comments

Comments

@xieyuyang
Copy link

xieyuyang commented May 30, 2019

Our program use mosquitto library to connect MQTT server.
When we call mosquitto_loop(), this function may returns MOSQ_ERR_INVAL.
And we find that mosq->sock is bigger than FD_SETSIZE(1024).

if(mosq->sock >= FD_SETSIZE || mosq->sockpairR >= FD_SETSIZE){
	return MOSQ_ERR_INVAL;
}

can you fix this issue?

Thanks!

@xieyuyang xieyuyang reopened this May 30, 2019
@ralight
Copy link
Contributor

ralight commented May 31, 2019

Are you using >1024 open files/sockets elsewhere? What platform are you running on?

@xieyuyang
Copy link
Author

Are you using >1024 open files/sockets elsewhere? What platform are you running on?

yes, socket fd > 1024. and our system is centos6.5.

@nedo99
Copy link

nedo99 commented Feb 21, 2020

Any updates on this one? I have the same problem.

I have two scenarios:

  • one with sending data with size ~66KB - works fine - no errors
  • one with sending big data ~310KB - MOSQ_ERR_INVAL - calling mosquitto_socket says socket is 1119.

OS: Ubuntu 18.04

Any ideas?

Regards,
Nedim

@karlp
Copy link
Contributor

karlp commented Feb 21, 2020

@nedo99 are you using a lot of fds in your user application? are you using mosquitto_loop()? If you are using a lot of fds in your own app, at least a workaround would be to use the mosquitto_loop_read, mosquitto_loop_write and mosquitto_loop_misc calls from your own fd handling mainloop (presumably then using (e)poll or one of the event libs)

if you're not using a lot of fds in your application, could you provide some more details?

@nedo99
Copy link

nedo99 commented Feb 21, 2020

@karlp yes we are using quite some fds. Not sure about the exact number.
I am using the mosquitto_loop and as mentioned for smaller data round 65KB it works fine, no errors, but with for instance 310KB, then I get invalid arguments error. Does this mean that for more data mosquitto opens even more fds in order to parallelize the transfer?

The only problem with read and write loops is that they are blocking calls and if there is a lot of data we cannot afford being blocked since sending data is not the highest priority.

@nedo99
Copy link

nedo99 commented Feb 24, 2020

Any other input?

@nedo99
Copy link

nedo99 commented Feb 24, 2020

I found a workaround for my case. I just put mosquitto initialization to be one of the first things in the code to get a valid socket (<1024).

IMO, this is the bug in the mosquitto_connect method since this method should not return success if the socket does not comply with FD_SETSIZE. The network loop will not work. At least some warning or something should be issued.

@erkoln
Copy link

erkoln commented Apr 7, 2023

Hello,
I am also experiencing this issue (app based on Intel DPDK, using LOTS of fds under-the-hood).
Thread started by mosquitto_loop_start will die silently, and spinning my own thread and calling mosquitto_loop I realized it returned MOSQ_ERR_EINVAL.
Securing several low fds (by way of dup(1) before initializing the DPDK library and closing them just before connecting to MQTT broker) allowed me to work around this issue, but it seems fragile (e.g. if my app loses its connection to broker and needs to re-connect).
It seems like it could be fixed by switching the pselect API for epoll_pwait.

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

5 participants