luci-app-nlbw: fix sporadic premature EOF when rendering JSON data
Specific timing patterns sometimes caused the LuCI controller to prematurely stop reading data, resulting in truncated JSON output. Turn the nonblocking waitpid() call into a blocking call after the IO read loop to avoid this issue. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
a441721d32
commit
08916f4335
1 changed files with 7 additions and 6 deletions
|
@ -28,16 +28,17 @@ local function exec(cmd, args, writer)
|
|||
|
||||
while true do
|
||||
local buffer = fdi:read(2048)
|
||||
local wpid, stat, code = nixio.waitpid(pid, "nohang")
|
||||
|
||||
if writer and buffer and #buffer > 0 then
|
||||
writer(buffer)
|
||||
end
|
||||
|
||||
if wpid and stat == "exited" then
|
||||
if not buffer or #buffer == 0 then
|
||||
break
|
||||
end
|
||||
|
||||
if writer then
|
||||
writer(buffer)
|
||||
end
|
||||
end
|
||||
|
||||
nixio.waitpid(pid)
|
||||
elseif pid == 0 then
|
||||
nixio.dup(fdo, nixio.stdout)
|
||||
fdi:close()
|
||||
|
|
Loading…
Reference in a new issue