From ca533f8937e77c256108ed7335037e95fd4374e8 Mon Sep 17 00:00:00 2001 From: Michael H Date: Fri, 23 Nov 2018 18:11:59 -0500 Subject: [PATCH] [JsonIO] race condition fix (#2308) * race condition fix * style fix --- redbot/core/json_io.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/redbot/core/json_io.py b/redbot/core/json_io.py index c610d7bb1..a2d01f73f 100644 --- a/redbot/core/json_io.py +++ b/redbot/core/json_io.py @@ -3,6 +3,7 @@ import json import os import asyncio import logging +from copy import deepcopy from uuid import uuid4 # This is basically our old DataIO and just a base for much more elaborate classes @@ -69,7 +70,11 @@ class JsonIO: async def _threadsafe_save_json(self, data, settings=PRETTY): loop = asyncio.get_event_loop() - func = functools.partial(self._save_json, data, settings) + # the deepcopy is needed here. otherwise, + # the dict can change during serialization + # and this will break the encoder. + data_copy = deepcopy(data) + func = functools.partial(self._save_json, data_copy, settings) async with self._lock: await loop.run_in_executor(None, func)