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

A pipe opened to mosquitto_sub cannot be closed from the script that opened it #2164

Closed
fuxoft opened this issue Apr 4, 2021 · 1 comment
Milestone

Comments

@fuxoft
Copy link

fuxoft commented Apr 4, 2021

I wrote a Lua script (for Linux) that opens a pipe to "mosquitto_sub" and reads incoming data from it. This works flawlessly. But when the script ends and I want to cleanly close the pipe, my script hangs indefinitely on the "fd:close()" line. I am not sure if this is a mosquitto_sub problem but I am using Lua pipes to read outputs of various CLI commands all the time and I have never experienced this behavior before - fd:close() should never hang.

This Lua script shows that closing a pipe to another command works OK but attempt to close a pipe to mosquitto_sub hangs. This script requires local mosquitto server running with default configuration so that the script can connect to it without authentication.

#!/usr/bin/env lua
local fd

print("Opening cat pipe")
fd = io.popen("cat /dev/null")
print("Trying to close cat pipe")
fd:close()
print("Closed cat pipe")

print("Opening mosquitto_sub pipe")
fd = io.popen("mosquitto_sub -t 'nonexistent_topic'")
print("Trying to close mosquitto_pub pipe")
fd:close()
print("Closed mosquitto_pub file") --This is never printed

ralight added a commit that referenced this issue Apr 6, 2021
If sending mosquitto_sub output to a pipe, mosquitto_sub will now detect
that the pipe has closed and disconnect.

Closes #2164. Thanks to Frantisek Fuka.
@ralight
Copy link
Contributor

ralight commented Apr 6, 2021

Thank you, that is now fixed in the fixes branch.

@ralight ralight added this to the 2.0.11 milestone Apr 6, 2021
@fuxoft fuxoft closed this as completed Apr 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 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