awestlake87 / pyo3-asyncio

Other
300 stars 45 forks source link

check future state right before setting result, fix #77 #79

Closed mhils closed 1 year ago

mhils commented 1 year ago

This PR fixes the race condition described in #77: Python's runtime could previously set a Future's result between pyo3-ayncio's cancelled check and its set_result callback, causing an InvalidStateException. This PR fixes this by doing the check immediately before setting the result.

Adding tests is tricky as we heavily rely on a race condition between the two runtimes, so I've skipped that. Lastly, the PR template mentions a CHANGELOG.md, but there is no such file. :)

Apart from these details, pyo3-asyncio has been fantastic to work with. Thank you very much for the work you're doing here! 😃🍰✨

mhils commented 1 year ago

Race condition indeed - @decathorpe was slightly faster than me in #78. 🫣 Please feel free to merge whatever you prefer, no hard feelings at all.

awestlake87 commented 1 year ago

Merged #78 and released it as 0.17 along with a regression test. Let me know if you see any issues downstream!