question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Race condition in "wait()" causes call to block infinitely

See original GitHub issue
  • 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.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dwalton76commented, May 10, 2019

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

0reactions
staadeckercommented, Apr 21, 2019

@dwalton76 . Unfortunately, when I tried to reproduce the issue, I could not (with the old code). So I can’t test whether it fixes anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix race condition for condition variable wait/notify
When unblocked, regardless of the reason, lock is reacquired and wait exits. If this function exits via exception, lock is also reacquired.
Read more >
How to Avoid Race Conditions in your Microservice Application
Race condition: two processes accessing the same resource at the same time may lead to inconsistencies;; Starvation: unreleased locks will make ...
Read more >
Thread safety in iOS to avoid race conditions/read and write ...
Deadlock : A deadlock is a condition when a program cannot access a resource it needs to continue because when threads are waiting...
Read more >
Fixing Race Conditions in React with useEffect - Max Rozen
So you've got a component that fetches data in React. The component accepts an id as a prop, uses the id to fetch...
Read more >
How do I avoid race conditions in WaitOnAddress where the ...
Now we're actually waiting for a condition, namely for the m_compare to become nonzero. This solves the race condition, because if an item...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found