New submission from tzickel <icebr...@yahoo.com>:

bpo 36051 added optimization to release GIL on certain conditions of bytes 
joining, but it has missed a critical path.

If the number of items joining is less or equal to NB_STATIC_BUFFERS (10) than 
static_buffers will be used to hold the buffers.

https://github.com/python/cpython/blob/5b66ec166b81c8a77286da2c0d17be3579c3069a/Objects/stringlib/join.h#L54

But then the decision to release the GIL or not (drop_gil) does not take this 
into consideration, and the GIL might be released and then another thread is 
free to do the same code path, and hijack the static_buffers for it's own 
usage, causing a race condition.

A decision should be made if it's worth for the optimization to not use the 
static buffers in this case (although it's an early part of the code...) or not 
drop the GIL anyhow if it's static buffers (a thing which might make this 
optimization not worth it, since based on length of data to join, and not 
number of items to join).

----------
messages: 364288
nosy: tzickel
priority: normal
severity: normal
status: open
title: A race condition with GIL releasing exists in stringlib_bytes_join
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39974>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to