[ST Edge] Driver Deep Sleep?

How would I go about using spawn for this?

cosock.spawn(function()
  while true do
    local data, ip, port = sock:receivefrom()
    handle_bpup_message(driver, device, ip, port, data)
  end
end, string.format('bpup callback %s', device:pretty_print()))

That would achieve the same thing as what register_socket is doing.

Does each device get its own thread?

Yes, each device gets its own Thread, which maps to a lua coroutine, which isn’t the same thing as an OS thread. The limitation here being that one 1 coroutine can be executing at a time and if a coroutine yields, it has to wait until it is selected to run again.

If I schedule something on the thread of Device A, would you expect it to impact Device B?

The only way one thread could impact another thread is by potentially being very busy w/o yielding. This isn’t probably likely what is happening for your driver.

Also, if it is these scheduled calls, why do you think it would only be slow after an extended downtime? Wouldn’t it always be slow?

This is a very good point, I had initially thought that we might be hitting a bit of a perfect storm where the same thread was being used for a poll loop and we just happened to be hitting the tail end of a sleep but raising this now makes me think you might be experiencing some extra delay because of the bug uncovered here.

Essentially we are leaking some memory associated with each socket created after it gets garbage collected and we end up performing the cleanup only when a new device event comes through. We have a bugfix in line for the next release so hopefully this will solve your problem.