ev3dev-lang-python: Race condition in "wait()" causes call to block infinitely

  • ev3dev version:

System info (from ev3dev-sysinfo)

Image file:         ev3dev-stretch-ev3-generic-2018-07-15
Kernel version:     4.14.71-ev3dev-2.3.0-ev3
Brickman:           0.10.0
BogoMIPS:           148.88
Board:              board0
BOARD_INFO_HW_REV=7
BOARD_INFO_MODEL=LEGO MINDSTORMS EV3
BOARD_INFO_ROM_REV=6
BOARD_INFO_SERIAL_NUM=00165340720B
BOARD_INFO_TYPE=main
  • ev3dev-lang-python version: current ev3dev-stretch branch

From https://github.com/ev3dev/ev3dev/issues/1200.

When running a series of small movements where the motor will almost immediately reach the target, we sometimes hit a case where our wait logic gets stuck. This is improved by the re-ordering we did recently of the relevant wait code, but nonetheless still happens (in a slightly different way).

https://github.com/ev3dev/ev3dev-lang-python/blob/056f721c383a8a4331f7cc7f9958ffdcf794e573/ev3dev2/motor.py#L849-L874

From what I can tell, we get through the check on line 868 and determine we can’t immediately return; so, we then call poll to block until something changes. In the time between when that happens and when the poll internals actually get around to checking, the state has been updated from running to holding and we’ve missed it. This causes the method to block indefinitely.

I don’t see an obvious solution to this. We could add a timeout when waiting for the motor to stop (so it would at least not freeze). Alternately, perhaps we could modify the code where we call poll so that it always uses a small timeout so we manually check occasionally even if poll missed it. This latter approach would degrade responsiveness in the general case but improve the edge case.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 21 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I am about 99% sure I was able to reproduce this and verify the fix so am going to close this one