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: stale frappe.local #20695

Merged
merged 2 commits into from
Apr 14, 2023
Merged

fix: stale frappe.local #20695

merged 2 commits into from
Apr 14, 2023

Conversation

ankush
Copy link
Member

@ankush ankush commented Apr 14, 2023

  • web.error.log shows that the web worker is failing to connect to the DB server.
  • The error message indicates web workers are not using site config at all and using the default username without a password for connecting.
  • Restarting the web workers fixed the issue.
[2023-04-09 08:12:31 +0000] [101928] [ERROR] Error handling request /api/method/ping
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 136, in handle
    self.handle_request(listener, req, client, addr)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/werkzeug/local.py", line 231, in application
    return ClosingIterator(app(environ, start_response), self.cleanup)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/werkzeug/wrappers/base_request.py", line 237, in application
    resp = f(*args[:-2] + (request,))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 97, in application
    for after_request_task in frappe.get_hooks("after_request"):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1363, in get_hooks
    hooks = _dict(cache().get_value("app_hooks", load_app_hooks))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 84, in get_value
    val = generator()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1337, in load_app_hooks
    for app in [app_name] if app_name else get_installed_apps(_ensure_on_bench=True):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1291, in get_installed_apps
    installed = json.loads(db.get_global("installed_apps") or "[]")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 884, in get_global
    return self.get_default(key, user)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 888, in get_default
    d = self.get_defaults(key, parent)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 905, in get_defaults
    defaults = frappe.defaults.get_defaults(parent)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/defaults.py", line 89, in get_defaults
    globald = get_defaults_for()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/defaults.py", line 238, in get_defaults_for
    as_dict=1,
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 161, in sql
    self.connect()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 85, in connect
    self._conn = self.get_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 85, in get_connection
    local_infile=frappe.conf.local_infile,
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 353, in __init__
    self.connect()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 633, in connect
    self._request_authentication()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 907, in _request_authentication
    auth_packet = self._read_packet()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'frappe'@'blablah.compute.internal' (using password: NO)")

It seems any exception thrown in finally block prevent locals from releasing, which means subsequent requests can end up serving with incorrect locals.

Full context: https://gameplan.frappe.cloud/g/frappe-cloud/projects/86/discussion/2250/

Credit: @adityahase for finding root cause.

@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label Apr 14, 2023
Co-Authored-By: Aditya Hase <aditya@adityahase.com>
@ankush ankush removed the add-test-cases Add test case to validate fix or enhancement label Apr 14, 2023
To ensure that any one bad request can not completely cause recurring
loop of broken requests due to bad locals, we just force-init locals on
every request.
@ankush ankush marked this pull request as ready for review April 14, 2023 04:05
@ankush ankush requested review from a team and shariquerik and removed request for a team April 14, 2023 04:05
@ankush ankush requested review from adityahase and phot0n and removed request for shariquerik April 14, 2023 04:06
@codecov
Copy link

codecov bot commented Apr 14, 2023

Codecov Report

Merging #20695 (782828f) into develop (76e576c) will increase coverage by 0.00%.
The diff coverage is 75.00%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #20695   +/-   ##
========================================
  Coverage    63.92%   63.92%           
========================================
  Files          758      758           
  Lines        68755    68761    +6     
  Branches      6208     6208           
========================================
+ Hits         43952    43956    +4     
- Misses       21279    21281    +2     
  Partials      3524     3524           
Flag Coverage Δ
server 68.84% <75.00%> (-0.02%) ⬇️

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

@ankush ankush merged commit 1e9ede4 into frappe:develop Apr 14, 2023
@ankush ankush deleted the stale_locals branch April 14, 2023 08:49
mergify bot pushed a commit that referenced this pull request Apr 14, 2023
* fix: stale `frappe.local`

Co-Authored-By: Aditya Hase <aditya@adityahase.com>

* fix: force re-init in request

To ensure that any one bad request can not completely cause recurring
loop of broken requests due to bad locals, we just force-init locals on
every request.

---------

Co-authored-by: Aditya Hase <aditya@adityahase.com>
(cherry picked from commit 1e9ede4)

# Conflicts:
#	frappe/__init__.py
#	frappe/app.py
mergify bot pushed a commit that referenced this pull request Apr 14, 2023
* fix: stale `frappe.local`

Co-Authored-By: Aditya Hase <aditya@adityahase.com>

* fix: force re-init in request

To ensure that any one bad request can not completely cause recurring
loop of broken requests due to bad locals, we just force-init locals on
every request.

---------

Co-authored-by: Aditya Hase <aditya@adityahase.com>
(cherry picked from commit 1e9ede4)
ankush added a commit that referenced this pull request Apr 14, 2023
* fix: stale `frappe.local`

Co-Authored-By: Aditya Hase <aditya@adityahase.com>

* fix: force re-init in request

To ensure that any one bad request can not completely cause recurring
loop of broken requests due to bad locals, we just force-init locals on
every request.

---------

Co-authored-by: Aditya Hase <aditya@adityahase.com>
(cherry picked from commit 1e9ede4)

Co-authored-by: Ankush Menat <ankush@frappe.io>
ankush added a commit that referenced this pull request Apr 14, 2023
* fix: stale `frappe.local` (#20695)

* fix: stale `frappe.local`

Co-Authored-By: Aditya Hase <aditya@adityahase.com>

* fix: force re-init in request

To ensure that any one bad request can not completely cause recurring
loop of broken requests due to bad locals, we just force-init locals on
every request.

---------

Co-authored-by: Aditya Hase <aditya@adityahase.com>
(cherry picked from commit 1e9ede4)

# Conflicts:
#	frappe/__init__.py
#	frappe/app.py

* chore: conflicts

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
frappe-pr-bot pushed a commit that referenced this pull request Apr 18, 2023
# [14.33.0](v14.32.1...v14.33.0) (2023-04-18)

### Bug Fixes

* allow filter values to be saved in custom report ([295d2b8](295d2b8))
* allow workflow action master rename ([2730f22](2730f22))
* bump poplib limit ([#20739](#20739)) ([#20740](#20740)) ([a58ef7a](a58ef7a))
* check communication subject existence before converting to text  ([#20738](#20738)) ([#20748](#20748)) ([3d047b4](3d047b4))
* clear all filters when in list view (backport [#20342](#20342)) ([#20746](#20746)) ([54d0dca](54d0dca))
* consider user email if send me a copy is checked ([#20627](#20627)) ([#20655](#20655)) ([3dc215d](3dc215d))
* **export:** Use fieldname if label is not set ([f497557](f497557))
* filter with capitalized operator was getting bypassed (backport [#20682](#20682)) ([#20684](#20684)) ([7831866](7831866))
* format filter values in report print view (backport [#20717](#20717)) ([#20752](#20752)) ([83fdb2e](83fdb2e))
* group buttons are overlapping (backport [#20671](#20671)) ([#20687](#20687)) ([149eed7](149eed7))
* Hide dropdown menu on click ([454f3a7](454f3a7))
* Load doc before checking permission ([a8348ce](a8348ce))
* make `owner` restricted ([8ad7ddb](8ad7ddb))
* Patch to update Background Jobs URL ([67add11](67add11))
* prioritize modal over freeze in grid-form ([953b331](953b331))
* Redirect Background Jobs to RQ Jobs ([2cc1092](2cc1092))
* Remove Background Jobs from dropdown ([0c7009c](0c7009c))
* remove desk access for Guest in post_model_sync ([#20719](#20719)) ([#20720](#20720)) ([97e0836](97e0836))
* remove guest permission from language ([#20677](#20677)) ([#20691](#20691)) ([de3b484](de3b484))
* Resolve conflicts ([a66fa64](a66fa64))
* Resolve conflicts ([abacaba](abacaba))
* route to form if name has slashes in it ([ae7d693](ae7d693))
* Show background jobs only to permitted users ([c065b2b](c065b2b))
* stale `frappe.local` ([#20695](#20695)) ([#20701](#20701)) ([2715d2d](2715d2d))
* update property if field exist ([3f10e63](3f10e63))
* use frappe.log_error in EmailServer exception handling ([25281e3](25281e3))
* **UX:** workspace breadcrumbs based on history ([#20529](#20529)) ([#20661](#20661)) ([260ef71](260ef71))

### Features

* redis cache decorator ([#20452](#20452)) ([3dff558](3dff558))
frappe-pr-bot pushed a commit that referenced this pull request Apr 18, 2023
# [13.54.0](v13.53.2...v13.54.0) (2023-04-18)

### Bug Fixes

* allow filter values to be saved in custom report ([2499aba](2499aba))
* allow workflow action master rename ([afc05c4](afc05c4))
* bulk update (backport [#20522](#20522)) ([8e51fb0](8e51fb0))
* clear all filters when in list view (backport [#20342](#20342)) ([#20747](#20747)) ([8fa1580](8fa1580))
* filter with capitalized operator was getting bypassed (backport [#20682](#20682)) ([#20683](#20683)) ([12cd78d](12cd78d))
* group buttons are overlapping (backport [#20671](#20671)) ([#20688](#20688)) ([b0183ed](b0183ed))
* Initialize "r" to avoid UnboundLocalError ([#19630](#19630)) ([#20758](#20758)) ([c852197](c852197))
* prioritize modal over freeze in grid-form ([ed85ea2](ed85ea2))
* remove guest permission from language (backport [#20677](#20677)) ([#20690](#20690)) ([2553a7e](2553a7e))
* Remove unnecessary code to avoid timestamp conflict ([410d976](410d976))
* stale `frappe.local` (backport [#20695](#20695)) ([#20700](#20700)) ([bfd9dd0](bfd9dd0))
* update property if field exist ([8171c65](8171c65))

### Features

* custom info in frappe monitor (backport [#18214](#18214)) ([#20686](#20686)) ([87d52f5](87d52f5)), closes [#18259](#18259)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant