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

simultaneous use of teletype queries and norns crow.send crashes crow #492

Open
Dewb opened this issue Dec 27, 2023 · 1 comment
Open

simultaneous use of teletype queries and norns crow.send crashes crow #492

Dewb opened this issue Dec 27, 2023 · 1 comment

Comments

@Dewb
Copy link
Contributor

Dewb commented Dec 27, 2023

When simultaneously receiving serial messages from norns and i2c query commands from Teletype, crow will eventually crash.

Crow can also be made to crash immediately by redefining the ii.self.query0 function while this is happening.

Example real-world application: adding an option to dreamsequence to synchronize its scale with teletype (branch)

The crash is observable in both crow 3.0.0 and crow 4.0.5.

Example repro script (this is not totally minimal, I believe one coroutine calling crow.send is sufficient, but more crash sooner.)

-- minimal script to reproduce teletype-crow-norns crash issue
-- steps to reproduce:
--   connect crow to teletype via i2c
--   put N.B CROW.Q0 in M script (default M 1000 is sufficient, but faster Ms crash sooner)
--   connect crow to norns via usb
--   run this script
--   crow will generally crash within 20-30 seconds. norns is hung until crow is disconnected or power cycled.

crow_updates = {}

function init()
  redraw()
  
  clock.run(function() 
    while true do
      update_crow(1)
      clock.sleep(0.5)
    end
  end)
  
  clock.run(function() 
    while true do
      update_crow(2)
      clock.sleep(0.17)
    end
  end)

  -- uncomment this to crash immediately  
  -- clock.run(function()
  --   clock.sleep(1)
  --   crow.send("ii.self.query0 = function() print('query0*') end")
  -- end)
end

function redraw()
  screen.clear()
  screen.level(15)
  screen.move(2,8)
  screen.text("crow stress test " .. os.clock())

  for i = 1, #crow_updates do
    if crow_updates[i] then
      screen.move(12, 20 + (i-1) * 12)
      screen.text("ran crow update " .. i)
      crow_updates[i] = false
    end
  end
  
  screen.update()
end

function refresh()
  redraw()
  update_crow(3)
end

function update_crow(n)
  norns.crow.send("foo = " .. n)
  crow_updates[n] = true
end
@Dewb
Copy link
Contributor Author

Dewb commented Dec 28, 2023

I had a chance to look at the i2c code and I see that based on the danger/fixme comments that this isn’t expected to work yet. I’d be happy to work on a PR to make the i2c queries safe, but I can imagine several different possible strategies with different tradeoffs, did anyone already have a plan in mind?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant