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

Mitigate Python 3.12 Shutdown RuntimeError #1925

Merged

Conversation

ppigazzini
Copy link
Collaborator

@ppigazzini ppigazzini commented Apr 4, 2024

Python 3.12 introduced a bug during the interpreter shutdown, see:

With Python 3.12.3, this change could potentially be reverted (after testing).

@ppigazzini ppigazzini added bug server server side changes labels Apr 4, 2024
@ppigazzini ppigazzini marked this pull request as draft April 4, 2024 16:42
@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Apr 4, 2024

Drafting, python 3.12 intentionally blocked the spawn of a new thread during the shutdown process, I found the official issue upstream (VanRossum involved!):
python/cpython#113964

EDIT: The fix for the RuntimeError issue has already been merged upstream. You can find the relevant pull request here below. With the release of Python 3.12.3, this error should no longer occur.
python/cpython#117029

@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Apr 4, 2024

For reference this is the strack trace in the log on DEV + few workers triggered with:

clear && sudo systemctl restart fishtest@{6543..6545} && sudo journalctl -u fishtest@6543 --since "10 minutes ago"
systemd[1]: Stopping Fishtest Server port 6543...
pserve[17032]: flush
pserve[17032]: .....................done
pserve[17032]: Exception in thread Thread-740:
pserve[17032]: Traceback (most recent call last):
pserve[17032]:   File "/home/fishtest/.pyenv/versions/3.12.2/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
pserve[17032]:     self.run()
pserve[17032]:   File "/home/fishtest/.pyenv/versions/3.12.2/lib/python3.12/threading.py", line 1431, in run
pserve[17032]:     self.function(*self.args, **self.kwargs)
pserve[17032]:   File "/home/fishtest/fishtest/server/fishtest/rundb.py", line 451, in flush_buffers
pserve[17032]:     self.start_timer()
pserve[17032]:   File "/home/fishtest/fishtest/server/fishtest/rundb.py", line 365, in start_timer
pserve[17032]:     self.timer.start()
pserve[17032]:   File "/home/fishtest/.pyenv/versions/3.12.2/lib/python3.12/threading.py", line 992, in start
pserve[17032]:     _start_new_thread(self._bootstrap, ())
pserve[17032]: RuntimeError: can't create new thread at interpreter shutdown
systemd[1]: Stopped Fishtest Server port 6543.

Python 3.12 introduced a bug during the interpreter shutdown, see:
- issue python/cpython#104826
- bugfix python/cpython#117029

With Python 3.12.3, this change could potentially be reverted (after testing).
@ppigazzini ppigazzini changed the title Mitigate Shutdown RuntimeError Mitigate Python 3.12 Shutdown RuntimeError Apr 4, 2024
@ppigazzini ppigazzini added the update code change to account external change (Stockfish, book etc.) label Apr 4, 2024
@ppigazzini ppigazzini marked this pull request as ready for review April 4, 2024 18:38
@ppigazzini ppigazzini merged commit c8173d2 into official-stockfish:master Apr 4, 2024
19 checks passed
@ppigazzini ppigazzini deleted the race_flush_all_buffers branch April 4, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug server server side changes update code change to account external change (Stockfish, book etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant