hotplug event handler must return :finish or :repeat (ArgumentError)
rgaufman opened this issue · 1 comments
rgaufman commented
I have a server with what appears to be a dodgy input device, I see this in syslog in a loop every minute or so
Feb 20 21:49:19 TimeBox-d90282788c64ddd78c60 kernel: [ 847.288660] usb 8-1.1: USB disconnect, device number 19
Feb 20 21:49:21 TimeBox-d90282788c64ddd78c60 kernel: [ 848.797035] usb 8-1.1: new low-speed USB device number 20 using xhci_hcd
Feb 20 21:49:21 TimeBox-d90282788c64ddd78c60 kernel: [ 848.904744] usb 8-1.1: New USB device found, idVendor=0458, idProduct=003a
Feb 20 21:49:21 TimeBox-d90282788c64ddd78c60 kernel: [ 848.904749] usb 8-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Feb 20 21:49:21 TimeBox-d90282788c64ddd78c60 kernel: [ 848.904752] usb 8-1.1: Product: USB Optical Mouse
Feb 20 21:49:21 TimeBox-d90282788c64ddd78c60 kernel: [ 848.904755] usb 8-1.1: Manufacturer: Genius
Feb 20 21:49:21 TimeBox-d90282788c64ddd78c60 kernel: [ 848.910498] input: Genius USB Optical Mouse as /devices/pci0000:00/0000:00:04.0/0000:02:00.0/usb8/8-1/8-1.1/8-1.1:1.0/0003:0458:003A.0013/input/input27
Feb 20 21:49:21 TimeBox-d90282788c64ddd78c60 kernel: [ 848.910733] hid-generic 0003:0458:003A.0013: input,hidraw0: USB HID v1.11 Mouse [Genius USB Optical Mouse] on usb-0000:02:00.0-1.1/input0
Feb 20 21:49:39 TimeBox-d90282788c64ddd78c60 kernel: [ 867.300761] i2c i2c-1: Failed to register i2c client ds1307 at 0x68 (-16)
Feb 20 21:50:10 TimeBox-d90282788c64ddd78c60 kernel: [ 897.984979] usb 8-1.1: USB disconnect, device number 20
Feb 20 21:50:12 TimeBox-d90282788c64ddd78c60 kernel: [ 899.496793] usb 8-1.1: new low-speed USB device number 21 using xhci_hcd
Feb 20 21:50:12 TimeBox-d90282788c64ddd78c60 kernel: [ 899.604442] usb 8-1.1: New USB device found, idVendor=0458, idProduct=003a
Feb 20 21:50:12 TimeBox-d90282788c64ddd78c60 kernel: [ 899.604445] usb 8-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Feb 20 21:50:12 TimeBox-d90282788c64ddd78c60 kernel: [ 899.604447] usb 8-1.1: Product: USB Optical Mouse
Feb 20 21:50:12 TimeBox-d90282788c64ddd78c60 kernel: [ 899.604449] usb 8-1.1: Manufacturer: Genius
Feb 20 21:50:12 TimeBox-d90282788c64ddd78c60 kernel: [ 899.610028] input: Genius USB Optical Mouse as /devices/pci0000:00/0000:00:04.0/0000:02:00.0/usb8/8-1/8-1.1/8-1.1:1.0/0003:0458:003A.0014/input/input28
Feb 20 21:50:12 TimeBox-d90282788c64ddd78c60 kernel: [ 899.610184] hid-generic 0003:0458:003A.0014: input,hidraw0: USB HID v1.11 Mouse [Genius USB Optical Mouse] on usb-0000:02:00.0-1.1/input0
This is causing my ruby code to crash:
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/libusb-0.6.4/lib/libusb/context.rb:418:in `block in on_hotplug_event': hotplug event handler must return :finish or :repeat (ArgumentError)
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/libusb-0.6.4/lib/libusb/context.rb:203:in `libusb_handle_events_timeout_completed'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/libusb-0.6.4/lib/libusb/context.rb:203:in `handle_events'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/libusb-0.6.4/lib/libusb/eventmachine.rb:97:in `block in eventmachine_add_pollfd'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/libusb-0.6.4/lib/libusb/eventmachine.rb:79:in `block in need_handle_events'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/libusb-0.6.4/lib/libusb/eventmachine.rb:78:in `each'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/libusb-0.6.4/lib/libusb/eventmachine.rb:78:in `need_handle_events'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run_machine'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from /data/deployer/timeagent/vendor/bundle/ruby/2.7.0/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run'
Feb 20 21:48:29 TimeBox-d90282788c64ddd78c60 bundle[20776]: from _run.rb:144:in `<main>'
My code is:
context = LIBUSB::Context.new
context.on_hotplug_event do |device, event|
if device.inspect.include?('HID')
Shared.logger.warn("USB Event: #{event} - Device: #{device.inspect} - Keyboard or Mouse")
next
end
Shared.logger.warn("USB Event: #{event} - Device: #{device.inspect}")
if EnvConfig.data_path.present?
case event
when :HOTPLUG_EVENT_DEVICE_ARRIVED
sleep 5 # Give a bit of time for the drive to be properly identified
new_drive_handler.run_once
DriveOptimiser.optimise
when :HOTPLUG_EVENT_DEVICE_LEFT
# Do nothing
end
end
:repeat
end
EventMachine.run do
Shared.logger.warn 'Starting Event Machine ...'
context.eventmachine_register
Shared.logger.warn 'Event Machine Started!'
end
Rebooting remotely doesn't help and I don't have physical access to this server.
Any solution to handle this in my ruby code to avoid crashing my app?
rgaufman commented
My bad, I did not have :repeat as the return statement!