URI: 
       tnetwork: fix another race in session.subscribe - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 152c6abb86f41e3fdf0992501f500571e806091b
   DIR parent 9505a203d8de6596f7bd9e04900652a613a7d998
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Wed, 12 Sep 2018 16:58:15 +0200
       
       network: fix another race in session.subscribe
       
       key in session.subscriptions does not imply key in session.cache
       
       Diffstat:
         M electrum/interface.py               |      10 ++++++----
       
       1 file changed, 6 insertions(+), 4 deletions(-)
       ---
   DIR diff --git a/electrum/interface.py b/electrum/interface.py
       t@@ -29,6 +29,7 @@ import sys
        import traceback
        import asyncio
        from typing import Tuple, Union
       +from collections import defaultdict
        
        import aiorpcx
        from aiorpcx import ClientSession, Notification
       t@@ -46,7 +47,7 @@ class NotificationSession(ClientSession):
        
            def __init__(self, *args, **kwargs):
                super(NotificationSession, self).__init__(*args, **kwargs)
       -        self.subscriptions = {}
       +        self.subscriptions = defaultdict(list)
                self.cache = {}
        
            async def handle_request(self, request):
       t@@ -70,12 +71,13 @@ class NotificationSession(ClientSession):
                    timeout)
        
            async def subscribe(self, method, params, queue):
       +        # note: until the cache is written for the first time,
       +        # each 'subscribe' call might make a request on the network.
                key = self.get_index(method, params)
       -        if key in self.subscriptions:
       -            self.subscriptions[key].append(queue)
       +        self.subscriptions[key].append(queue)
       +        if key in self.cache:
                    result = self.cache[key]
                else:
       -            self.subscriptions[key] = [queue]
                    result = await self.send_request(method, params)
                    self.cache[key] = result
                await queue.put(params + [result])