lain icon indicating copy to clipboard operation
lain copied to clipboard

Net widget causes random crashes

Open juacq97 opened this issue 5 years ago • 4 comments

Hi! I want to use the net widget, here's my code:

 local mynet = lain.widget.net {
    iface = "wlp3s0",
    wifi_state = "on",
    settings = function()
       local wifi = net_now.devices.wlp3s0
       if wifi then
 	 net = "Connected"
       else
 	 net = "Disconnected"
       end
       widget:set_markup(net)
    end
 }

And I have my wibox setup:

    s.mywibox:setup {
       layout = wibox.layout.align.horizontal,
        { -- Left widgets
            layout = wibox.layout.fixed.horizontal,
            s.mylayoutbox,
            s.mytaglist,
        },
	mytextclock,
	expand = "none",
        { -- Right widgets
            layout = wibox.layout.fixed.horizontal,
	    myvol,
	    mysep,
	    mysep,
	    mybat,
	    mysep,
	    mysep,
	    mytemp,
	    mysep,
	    mysep,
	    mynet,
	    mysep,
        },

(Those mysep are just textboxes with spaces). When I restart awesome (including when I turn on the pc) sometimes I get an error. If I restart again the error is solved. After deactivating and activating all the widgets I conclude that is net the cause of the problem. There's some issue with my config file? Thanks! awesome_error

juacq97 avatar Oct 01 '20 04:10 juacq97

same problem, Is there a way to solve this?

v6cc avatar Dec 02 '20 13:12 v6cc

I was fighting this since yesterday when I started using this widget. The intermittent nature of the error really makes it difficult to debug. I tried many things to isolate it, but haven't found how to solve this in the lain code.

However, I did find a workaround:

  1. Don't put the lain.widget.net into your wibox!
  2. Create separate widgets to display the info from lain.widget.net and use those in your wibox.

Here's my use case which is adapted from copycats:

-- Net
local netdownicon = wibox.widget.imagebox(beautiful.widget_netdown)
local netdowninfo = wibox.widget.textbox()
local netupicon = wibox.widget.imagebox(beautiful.widget_netup)
local netupinfo = wibox.widget.textbox()

-- NOTE: actually using this widget in the wibar doesn't work reliably!
--      as shown on the lain wiki it will error on awesome reload intermittently!
--      this is caused by it trying to set 'devices' when the widget is "read only" ???
--      My solution is to use separate textbox widgets for display in wibar.
local netinfo = lain.widget.net({
    settings = function()
        netupinfo:set_markup(markup.fontfg(beautiful.font, "#e54c62", net_now.sent .. " "))
        netdowninfo:set_markup(markup.fontfg(beautiful.font, "#87af5f", net_now.received .. " "))
    end
})

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- in the s.mywibox:setup right widgets block:
  
  netdownicon,
  netdowninfo,
  netupicon,
  netupinfo,

imabuddha avatar Jan 20 '21 02:01 imabuddha

I might have found the problem, and I believe the underlying reason is because the net widget is implemented by using a generic table.

-- ...
local function factory(args)
    args             = args or {}

    -- The line below is the line that causes all the problems
    local net        = { widget = args.widget or wibox.widget.textbox(), devices = {} }
    local timeout    = args.timeout or 2
    local units      = args.units or 1024 -- KB
    local notify     = args.notify or "on"
    local wifi_state = args.wifi_state or "off"
    local eth_state  = args.eth_state or "off"

   -- ...

   return net
end

From: https://github.com/lcpz/lain/blob/master/widget/net.lua#L20

The solution would be to actually use the wibox.widget.base.make_widget function that awesome provides.

The reason why I believe the generic table method breaks, because of how awesomewm parses widget layouts. After some digging in the awesomewm source code I couldn't really figure out exactly "why" it crashes. But I am really confident that after refactor the widget to use wibox.widget.base.make_widget would solve this problem.

RokasPuzonas avatar Jan 13 '22 11:01 RokasPuzonas

I was fighting this since yesterday when I started using this widget. The intermittent nature of the error really makes it difficult to debug. I tried many things to isolate it, but haven't found how to solve this in the lain code.

However, I did find a workaround:

1. Don't put the lain.widget.net into your wibox!

2. Create separate widgets to display the info from lain.widget.net and use _those_ in your wibox.

Here's my use case which is adapted from copycats:

-- Net
local netdownicon = wibox.widget.imagebox(beautiful.widget_netdown)
local netdowninfo = wibox.widget.textbox()
local netupicon = wibox.widget.imagebox(beautiful.widget_netup)
local netupinfo = wibox.widget.textbox()

-- NOTE: actually using this widget in the wibar doesn't work reliably!
--      as shown on the lain wiki it will error on awesome reload intermittently!
--      this is caused by it trying to set 'devices' when the widget is "read only" ???
--      My solution is to use separate textbox widgets for display in wibar.
local netinfo = lain.widget.net({
    settings = function()
        netupinfo:set_markup(markup.fontfg(beautiful.font, "#e54c62", net_now.sent .. " "))
        netdowninfo:set_markup(markup.fontfg(beautiful.font, "#87af5f", net_now.received .. " "))
    end
})

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- in the s.mywibox:setup right widgets block:
  
  netdownicon,
  netdowninfo,
  netupicon,
  netupinfo,

Thank you, this method works just fine for me, the intermittent error is gone.

xfzv avatar Apr 18 '23 17:04 xfzv