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

fix(timepicker): make pyparsing thread safe #12489

Merged
merged 2 commits into from
Jan 13, 2021

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Jan 13, 2021

SUMMARY

make pyparsing thread-safe

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

  1. run superset with below
 gunicorn -w 1 --threads 64 -b "0.0.0.0:8088" "superset.app:create_app()"
  1. open world bank's data dashboard without error

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@junlincc
Copy link
Member

junlincc commented Jan 13, 2021


thanks for the fix!!
With lock
Screen Shot 2021-01-13 at 1 50 14 AM

Without lock(consistently getting error by refreshing page)
Screen Shot 2021-01-13 at 1 49 47 AM
Screen Shot 2021-01-13 at 1 56 55 AM
Screen Shot 2021-01-13 at 1 56 46 AM
Screen Shot 2021-01-13 at 2 02 05 AM

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to fix it consistently for me in local dev env. Let's merge this quickly to unblock master and continue refining/optimizing perf later.

Copy link
Member

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix, but if pyparser is not thread safe we should start working on removing this dependency

@junlincc
Copy link
Member

junlincc commented Jan 13, 2021

Thank you for the fix, but if pyparser is not thread safe we should start working on removing this dependency

I will hate to see this new feature go, so will many other users, as we already receive some positive feedback from the community. we should figure out a way to fix it forward instead of simply removing the dependency, right? @dpgaspar

@zhaoyongjie zhaoyongjie changed the title fix: make pyparsing thread safe fix(timepicker): make pyparsing thread safe Jan 13, 2021
@codecov-io
Copy link

codecov-io commented Jan 13, 2021

Codecov Report

Merging #12489 (fb1a96a) into master (e9d66e9) will decrease coverage by 6.95%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12489      +/-   ##
==========================================
- Coverage   66.12%   59.16%   -6.96%     
==========================================
  Files        1015      959      -56     
  Lines       49554    46791    -2763     
  Branches     5079     4341     -738     
==========================================
- Hits        32767    27684    -5083     
- Misses      16647    19107    +2460     
+ Partials      140        0     -140     
Flag Coverage Δ
cypress 50.99% <ø> (+5.49%) ⬆️
javascript ?
python 63.77% <100.00%> (-0.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/utils/date_parser.py 95.13% <100.00%> (+0.02%) ⬆️
...uperset-frontend/src/dashboard/util/dnd-reorder.js 0.00% <0.00%> (-100.00%) ⬇️
...rset-frontend/src/dashboard/util/getEmptyLayout.js 0.00% <0.00%> (-100.00%) ⬇️
...dashboard/components/resizable/ResizableHandle.jsx 0.00% <0.00%> (-100.00%) ⬇️
.../src/dashboard/util/getFilterScopeFromNodesTree.js 0.00% <0.00%> (-93.48%) ⬇️
...set-frontend/src/views/CRUD/alert/ExecutionLog.tsx 11.76% <0.00%> (-88.24%) ⬇️
...src/dashboard/components/gridComponents/Header.jsx 10.52% <0.00%> (-86.85%) ⬇️
superset-frontend/src/components/IconTooltip.tsx 13.33% <0.00%> (-86.67%) ⬇️
...rc/dashboard/components/gridComponents/Divider.jsx 13.33% <0.00%> (-86.67%) ⬇️
...end/src/SqlLab/components/ExploreResultsButton.jsx 8.00% <0.00%> (-84.00%) ⬇️
... and 415 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9d66e9...fb1a96a. Read the comment docs.

@villebro villebro added the v1.0 label Jan 13, 2021
@dpgaspar
Copy link
Member

right @junlincc we should figure out a way to replace the dependency (without removing the feature) not sure if our dependency is light or not. But this needs a more detailed analysis.
I may be wrong but there is the probability that this lock will not be the end of this problem

@ktmud
Copy link
Member

ktmud commented Jan 13, 2021

I think I may have found another fix:

diff --git a/superset/utils/date_parser.py b/superset/utils/date_parser.py
index aee2c83a0..513c740ab 100644
--- a/superset/utils/date_parser.py
+++ b/superset/utils/date_parser.py
@@ -33,6 +33,7 @@ from pyparsing import (
     Optional as ppOptional,
     ParseException,
     ParseResults,
+    ParserElement,
     pyparsing_common,
     quotedString,
     Suppress,
@@ -40,6 +41,8 @@ from pyparsing import (
 
 from .core import memoized
 
+ParserElement.enablePackrat()
+
 logger = logging.getLogger(__name__)
 
 
@@ -375,7 +378,7 @@ class EvalHolidayFunc:  # pylint: disable=too-few-public-methods
         raise ValueError(_("Unable to find such a holiday: [{}]").format(holiday))
 
 
-@memoized()
+@memoized
 def datetime_parser() -> ParseResults:  # pylint: disable=too-many-locals
     (  # pylint: disable=invalid-name
         DATETIME,

Could you test this diff and see if it fixes things for you?

@ktmud
Copy link
Member

ktmud commented Jan 13, 2021

Enabling packrat cache seems to have fixed it for me.

I'd assume no other programs are using pyparsing so this should be relatively safe.

@ktmud
Copy link
Member

ktmud commented Jan 13, 2021

Looks like packrat cache comes with a lock for free: https://github.com/pyparsing/pyparsing/blob/f10fcf8c98ea07a63f8286288ce82f773e7e152e/pyparsing/core.py#L719

So I'm 90% sure this will fix the bug... (with the additional benefit of making things a little faster).

@villebro
Copy link
Member

villebro commented Jan 13, 2021

Looks like packrat cache comes with a lock for free: https://github.com/pyparsing/pyparsing/blob/f10fcf8c98ea07a63f8286288ce82f773e7e152e/pyparsing/core.py#L719

So I'm 90% sure this will fix the bug... (with the additional benefit of making things a little faster).

I can confirm that this fixes the problem for me, too 👏 This looks like the perfect solution for this case.

@zhaoyongjie zhaoyongjie force-pushed the fix_pyparsing_thread_safe_issue branch from fb1a96a to 24c108b Compare January 13, 2021 11:52
@zhaoyongjie
Copy link
Member Author

Looks like packrat cache comes with a lock for free: https://github.com/pyparsing/pyparsing/blob/f10fcf8c98ea07a63f8286288ce82f773e7e152e/pyparsing/core.py#L719

So I'm 90% sure this will fix the bug... (with the additional benefit of making things a little faster).

I changed this PR to add ParserElement.enablePackrat() and enable cache for datetime_parser, thank you for your finger out this solution

@villebro villebro merged commit b22e458 into apache:master Jan 13, 2021
villebro pushed a commit to preset-io/superset that referenced this pull request Jan 13, 2021
* fix: make pyparsing thread safe

* remove parenthesis for decorator
@junlincc
Copy link
Member

countless thanks to you all for resolving this.🙏 @ktmud @villebro @zhaoyongjie

villebro pushed a commit that referenced this pull request Jan 13, 2021
* fix: make pyparsing thread safe

* remove parenthesis for decorator
@mistercrunch
Copy link
Member

This was easily one of the ugliest bug in Superset history: elusive, hard to reproduce, thread-safety-related, ...

Good work tracking it down and finding a viable fix for this one!

amitmiran137 pushed a commit to nielsen-oss/superset that referenced this pull request Jan 14, 2021
* fix: make pyparsing thread safe

* remove parenthesis for decorator
@zhaoyongjie zhaoyongjie deleted the fix_pyparsing_thread_safe_issue branch January 16, 2021 04:19
etr2460 pushed a commit that referenced this pull request Jan 25, 2021
* release: bump to 1.0.0 and CHANGELOG

* fix(explore): long metric name display (#12387)

* fix(explore): long metric name display

* add tooltip to control

* chore: Show datasets when search input is empty (#12391)

* chore: Fix typo “Rest” to “Reset” (#12392)

* chore: upgrade eslint, babel, and prettier (#12393)

* feat(explore): add tooltip to timepicker label (#12401)

* chore: change Datasource to Dataset in Explore ui (#12402)

* chore(explore):change dataset to datasource in ui

* modal

* Add space

* Changing it back🤦🏾‍♀️

* Chargeback

* fix: Refresh Interval Modal dropdown (#12406)

* fix(native-filters): incorrect queriesData state (#12409)

* refactor: from superset.utils.core break down date_parser (#12408)

* Fixes control panel fields styling (#12236) (#12326)

* feat: Resizable dataset and controls panels on Explore view (#12411)

* Implement resizable panels on explore view

* Optimize chart rendering while resizing

* Make dataset column narrower

Co-authored-by: Evan Rusackas <evan@preset.io>

* fix(dashboard): artefacts shown while drag and dropping deck.gl charts (#12418)

* [12181] Fix artifacts while drag and dropping deck.gl charts.

* Run prettier

* bump superset-ui packages for rolling window change (#12426)

* chore: bump superset-ui deckgl plugin (#12466)

* fix: do not show vertical scrollbar for charts in dashboard (#12478)

* fix: do not show vertical scrollbar for charts in dashboard

* Proper fix for #11419

Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>

* fix(dashboard): use datasource id from slice metadata (#12483)

* fix(timepicker): make pyparsing thread safe (#12489)

* fix: make pyparsing thread safe

* remove parenthesis for decorator

* fix (SQL Lab): disappearing results on tab switch (#12472)

* fix (SQL Lab): disappearing results on tab switch

* Remove state

* Fix test

* fix: import ZIP files that have been modified (#12425)

* fix: import ZIP files that have been modified

* Add unit test

* update changelog with rc2 entries

* fix: impose dataset ownership check on old API (#12491)

* fix: impose dataset ownership check on old API

* update UPDATING.md

* partially protect the old MVC also

* prevent metric and column add and update

* ci: remove refs/tags from docker tags on a release (#12518)

* ci: remove refs/tags from docker tags on a release

* wider head

* fix: lowercase all columns in examples (#12530)

* fix(explore): time table control panel (#12532)

* fix(explore): Add Time section back to FilterBox (#12537)

* Fixing Pinot queries for time granularities: WEEKS/MONTHS/QUARTERS/YEARS (#12536)

* fix: Select options overflowing Save chart modal on Explore view (#12522)

* Fix select options overflowing modal

* fix unit test

Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>

* Fix list filters vertical alignment (#12497)

* feat(db-engine): Add support for Apache Solr (#12403)

* [db engine] Add support for Apache Solr

* Fixing typo

* chore: rename docker image in build_docker_image.sh, docker-compose.yml and helm values.yaml (#12337)

* add rc3 changelog entries

* fix: Popover closes on change of dropdowns values (#12410)

* fix: Add MAX_SQL_ROW value to LIMIT_DROPDOWN (#12555)

* fix(viz): missing groupby and broken adhoc metrics for boxplot (#12556)

* fix: height on grid results (#12558)

* fix: case expression should not have double quotes (#12562)

* Fix 500 error when loading dashboards with slice having deleted dataset (#12535)

* add rc4 changelog entries

* Fixed typo on line 348

* Added files

Co-authored-by: Daniel Gaspar <danielvazgaspar@gmail.com>
Co-authored-by: Yongjie Zhao <yongjie.zhao@gmail.com>
Co-authored-by: Geido <60598000+geido@users.noreply.github.com>
Co-authored-by: Junlin Chen <junlin@preset.io>
Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>
Co-authored-by: Agata Stawarz <47450693+agatapst@users.noreply.github.com>
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Kamil Gabryjelski <kamil.gabryjelski@gmail.com>
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Kasia Kucharczyk <2536609+kkucharc@users.noreply.github.com>
Co-authored-by: Phillip Kelley-Dotson <pkelleydotson@yahoo.com>
Co-authored-by: Grace Guo <grace.guo@airbnb.com>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
Co-authored-by: Xiang Fu <fx19880617@gmail.com>
Co-authored-by: Ahmed Adel <github@aadel.io>
Co-authored-by: Amit Miran <47772523+amitmiran137@users.noreply.github.com>
Co-authored-by: Hugh A. Miles II <hughmil3s@gmail.com>
Co-authored-by: Shuyao Bi <shuyaob@andrew.cmu.edu>
Co-authored-by: Lyndsi Kay Williams <lyndsikaywilliams@Lyndsis-MacBook-Pro.local>
@mistercrunch mistercrunch added 🍒 1.0.0 🍒 1.0.1 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS v1.0 🍒 1.0.0 🍒 1.0.1 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants