[V3 json] race condition fix #2308

Merged
mikeshardmind merged 2 commits from V3/json-deepcopy into V3/release/3.0.0 2018-11-24 00:12:00 +01:00
mikeshardmind commented 2018-11-23 01:26:28 +01:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

This fixes a potential race condition which could cause the dictionary to be written to change during serialization.

### Type - [X] Bugfix - [ ] Enhancement - [ ] New feature ### Description of the changes This fixes a potential race condition which could cause the dictionary to be written to change during serialization.
tekulvw (Migrated from github.com) reviewed 2018-11-23 01:26:28 +01:00
mikeshardmind commented 2018-11-23 01:28:01 +01:00 (Migrated from github.com)

Traceback (caused by nickname tracking on high event servers with previous behavior)

[17/11/2018 05:04] ERROR events on_error 188: Exception in member_update
Traceback (most recent call last):
  File "/root/.local/lib/python3.6/site-packages/discord/client.py", line 225, in _run_event
    await coro(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/redbot/cogs/mod/mod.py", line 1674, in on_member_update
    nick_list.pop(0)
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/config.py", line 57, in __aexit__
    await self.value_obj.set(self.raw_value)
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/config.py", line 153, in set
    await self.driver.set(*self.identifiers, value=value)
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/drivers/red_json.py", line 112, in set
    await self.jsonIO._threadsafe_save_json(self.data)
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/json_io.py", line 74, in _threadsafe_save_json
    await loop.run_in_executor(None, func)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/json_io.py", line 54, in _save_json
    json.dump(data, f, **settings)
  File "/usr/lib/python3.6/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/usr/lib/python3.6/json/encoder.py", line 430, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.6/json/encoder.py", line 356, in _iterencode_dict
    for key, value in items:
RuntimeError: dictionary changed size during iteration
Traceback (caused by nickname tracking on high event servers with previous behavior) ```py [17/11/2018 05:04] ERROR events on_error 188: Exception in member_update Traceback (most recent call last): File "/root/.local/lib/python3.6/site-packages/discord/client.py", line 225, in _run_event await coro(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/redbot/cogs/mod/mod.py", line 1674, in on_member_update nick_list.pop(0) File "/usr/local/lib/python3.6/dist-packages/redbot/core/config.py", line 57, in __aexit__ await self.value_obj.set(self.raw_value) File "/usr/local/lib/python3.6/dist-packages/redbot/core/config.py", line 153, in set await self.driver.set(*self.identifiers, value=value) File "/usr/local/lib/python3.6/dist-packages/redbot/core/drivers/red_json.py", line 112, in set await self.jsonIO._threadsafe_save_json(self.data) File "/usr/local/lib/python3.6/dist-packages/redbot/core/json_io.py", line 74, in _threadsafe_save_json await loop.run_in_executor(None, func) File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.6/dist-packages/redbot/core/json_io.py", line 54, in _save_json json.dump(data, f, **settings) File "/usr/lib/python3.6/json/__init__.py", line 179, in dump for chunk in iterable: File "/usr/lib/python3.6/json/encoder.py", line 430, in _iterencode yield from _iterencode_dict(o, _current_indent_level) File "/usr/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict yield from chunks File "/usr/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict yield from chunks File "/usr/lib/python3.6/json/encoder.py", line 356, in _iterencode_dict for key, value in items: RuntimeError: dictionary changed size during iteration ```
Tobotimus (Migrated from github.com) approved these changes 2018-11-24 00:11:15 +01:00
Tobotimus (Migrated from github.com) left a comment

Appreciate the change. IMO whole JSON backend needs to be chopped, changed and possibly deprecated - will be more of a long term goal though.

Appreciate the change. IMO whole JSON backend needs to be chopped, changed and possibly deprecated - will be more of a long term goal though.
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2308
No description provided.