brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.27k stars 620 forks source link

Conky stalls shutdown when Conky calls lua scripts #822

Closed LinuxOnTheDesktop closed 5 years ago

LinuxOnTheDesktop commented 5 years ago

Issue

Often, my computer is slow to shutdown when running Conky. The problem occurs with Conky >= 1.11.1. More specifially, git bisect suggests the following.

 2a0d2a741a63b2478d879e7928e5719e3ab24c0f is the first bad commit
commit 2a0d2a741a63b2478d879e7928e5719e3ab24c0f
Author: Dan McCombs <dan.mccombs@oracle.com>
Date:   Mon Dec 3 15:00:46 2018 -0500

    Add draw_blended to convert.lua script so that it is converted to boolean properly from old configuration formats. (#689)

:040000 040000 45705563c21a58a5e8404a4b2a2f9a93405e4343 7598c39267fcd16e3b7a2b74673ab60f561dacf1 M  extras

With builds prior to that version, or with my lua scripts disabled, Conky shuts down fine. However, the problem is intermittent and my checking (of whether the stall was present with each commit) could have been more thorough.

Information Linux Mint 19.1 x64 Cinnamon. Conky version: see above.

This lua script suffices to trigger the problem:


#!/usr/bin/env lua

debug                               = false

bash_chkPwr                         = "acpi -a | grep on-line"

col_1                               = "${color1}"
col_2                               = "${color5}"
charString_1                        = "⊷"
charString_2                        = "⊶"

ticks_needed_powerChk               = 33

local rtnTxt                        = ""
local ticks
local ticks_needed_main             = 6
local ticks_increment_main          = 2
local power_current
local widgetStateToggle             = 0

function osCapture ( cmd )
    if debug then
        print("Command is: " .. cmd)
    end
    local f = assert( io.popen (cmd, 'r') )
    local s = assert( f:read('*a') )
    f:close()
    return s
end

function ticks_getCurrent ()
    return tonumber ( conky_parse ( "${updates}" ) )
end

function getPwrState ()
    local output = osCapture ( bash_chkPwr )
    if string.len ( output ) == 0 then return "b" end
    return "m"
end

function isTime_chckPwer ()
    if ( ( ticks % ticks_needed_powerChk ) == 0 ) then return true end
    return false
end

-- MAIN function (the one called by Conky)
function conky_flipFlop ()
    local newPower

    if debug then
        ticks = ticks_needed_powerChk --test
    else
        -- Conky window exists?
        if conky_window == nil then return end
        -- Get Conky ticks
        ticks = ticks_getCurrent()
    end

    -- Time to check power state?
    if isTime_chckPwer then
        if power_current == "" then
            power_current = getPwrState()
        else
            newPower = getPwrState()
            if power_current ~= newPower then
                if newPower == "b" then
                    ticks_needed_main = ticks_needed_main + ticks_increment_main
                else
                    ticks_needed_main = ticks_needed_main - ticks_increment_main
                end
                power_current = newPower
            end
        end
    end

    if ( ticks % ticks_needed_main == 0 ) then
        if widgetStateToggle == 0 then
            rtnTxt = col_1 .. charString_1
            widgetStateToggle = 1
        else
            rtnTxt = col_2 .. charString_2
            widgetStateToggle = 0
        end
    end
    return rtnTxt
end

--[[
===========================
AUTOEXECUTE - for testing
===========================]]

-- if debug then
--  conky_flipFlop() -- for testing
-- end

-- ## EOF ##
lasers commented 5 years ago

More specifially, git bisect suggests the following.

Confirmed? Tested more than once? I'm not familiar with code, but the offending commit seems unlikely because convert.lua is used to convert old configs to v1.10 lua syntax, I assume, always at startup.

You can read up on syntax differences between 1.9 and earlier versions and 1.1.0 and later versions. https://github.com/brndnmtthws/conky/wiki/Configurations

However, the problem is intermittent and my checking (of whether the stall was present with each commit) could have been more thorough.

I guess not confirmed. The commit seems to add support for old config draw_blended yes to draw_blended = true. Also, draw_blended is added in v1.11.0 (11th iteration) so one could argue that this ought be ignored in old configs instead... to encourage users to use newer configs.

It just seems unlikely to me right now. Maybe try again.

LinuxOnTheDesktop commented 5 years ago

Lasers,

Were you to supply me with the requisite two git checkout commands - one for the source with this commit, one for the source before that - then that would make it easier for me to test my hypothesis more thoroughly.

It may be that the commit does something unintended.

lasers commented 5 years ago

git log shows logs. git log -p will show code too. For you, use git log --oneline. From there, grep, less, etc.

git checkout 2a0d2a7 # offending git checkout e5e9e43 # right before offending

Cheers.

LinuxOnTheDesktop commented 5 years ago

I may have confused concurrence with causation - the problem may have been a script I called from conky (and it is not even a lua script) rather than conky itself. Closing.

LinuxOnTheDesktop commented 5 years ago

It might be worth adding the following observation.

The cause of my shutdown stalls was a bash script run by Conky. The script ran a network command, repeatedly, and from within a for loop. I do not know whether it is the responsibility of conky or of the bash script to ensure that instances of the command in question terminate properly. Perhaps it is the latter's responsibility. Anyhow, the problem can be fixed at the bash level, as follows.

for (( c=1; c<"$threshold_seconds" ; c++ )) ; do
        read -r signal < <(\
            timeout -k1 2 \
            iwconfig "$interface" | grep Signal | awk '{ print $4 }' | cut -d "=" -f 2 \
            &)
        cmd_pid=$! ; wait $cmd_pid
        # Use the 'wait' command, and the backgrounding above (the '&') to allow proper termination of the network command, despite the peculiarities of loops in Bash. The 'timeout' is in their for good measure (but will itself not work if one uses a simpler way of reading the output of the 'iwconfig' command into the variable!).
        sleep 1
    done