GitHub user BryanCutler opened a pull request:

    https://github.com/apache/spark/pull/17193

    [SPARK-19348][PYTHON] PySpark keyword_only decorator is not thread-safe

    ## What changes were proposed in this pull request?
    The `@keyword_only` decorator in PySpark is not thread-safe.  It writes 
kwargs to a static class variable in the decorator, which is then retrieved 
later in the class method as `_input_kwargs`.  If multiple threads are 
constructing the same class with different kwargs, it becomes a race condition 
to read from the static class variable before it's overwritten.  See 
[SPARK-19348](https://issues.apache.org/jira/browse/SPARK-19348) for 
reproduction code.
    
    This change will write the kwargs to a member variable so that multiple 
threads can operate on separate instances without the race condition.  It does 
not protect against multiple threads operating on a single instance, but that 
is better left to the user to synchronize.
    
    ## How was this patch tested?
    Added new unit tests for using the keyword_only decorator and a regression 
test that verifies `_input_kwargs` can be overwritten from different class 
instances.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/BryanCutler/spark 
pyspark-keyword_only-threadsafe-SPARK-19348-2_1

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/17193.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #17193
    
----
commit 945c54d0f125346dd6d0ad4739665e6529d19712
Author: Bryan Cutler <[email protected]>
Date:   2017-03-07T18:53:51Z

    made keyword_only decorator thread-safe by saving _input_kwargs to self

commit 7700f076a3bc7117ae274a7963d6262e54d38696
Author: Bryan Cutler <[email protected]>
Date:   2017-03-07T18:55:22Z

    added keyword_only tests, including a regression test

commit 7056b4d5cf160b9ef047f2fffc3591b145c44995
Author: Bryan Cutler <[email protected]>
Date:   2017-03-07T18:57:50Z

    updated _input_kwargs usage in pyspark-ml

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to