We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Crashing on Boot
$ python src/bitmessagemain.py 
Loading existing config files from /home/.config/PyBitmessage/
2018-08-05 13:19:02,170 - WARNING - Using default logger configuration
2018-08-05 13:19:02,592 - CRITICAL - Unhandled exception
Traceback (most recent call last):
  File "src/bitmessagemain.py", line 507, in <module>
  File "src/bitmessagemain.py", line 503, in main
  File "src/bitmessagemain.py", line 276, in start
  File "PyBitmessage/src/knownnodes.py", line 100, in readKnownNodes
    pickle_deserialize_old_knownnodes(source)
  File "PyBitmessage/src/knownnodes.py", line 63, in pickle_deserialize_old_knownnodes
    knownNodes = pickle.load(source)
  File "/usr/lib/python2.7/pickle.py", line 1384, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 864, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 886, in load_eof
    raise EOFError
EOFError
Cleaning up lockfile


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/knownnodes.py`
Content:
```
1 import json
2 import os
3 import pickle
4 # import sys
5 import threading
6 import time
7 
8 import state
9 from bmconfigparser import BMConfigParser
10 from debug import logger
11 
12 knownNodesLock = threading.Lock()
13 knownNodes = {stream: {} for stream in range(1, 4)}
14 
15 knownNodesTrimAmount = 2000
16 
17 # forget a node after rating is this low
18 knownNodesForgetRating = -0.5
19 
20 DEFAULT_NODES = (
21     state.Peer('5.45.99.75', 8444),
22     state.Peer('75.167.159.54', 8444),
23     state.Peer('95.165.168.168', 8444),
24     state.Peer('85.180.139.241', 8444),
25     state.Peer('158.222.217.190', 8080),
26     state.Peer('178.62.12.187', 8448),
27     state.Peer('24.188.198.204', 8111),
28     state.Peer('109.147.204.113', 1195),
29     state.Peer('178.11.46.221', 8444)
30 )
31 
32 
33 def json_serialize_knownnodes(output):
34     """
35     Reorganize knownnodes dict and write it as JSON to output
36     """
37     _serialized = []
38     for stream, peers in knownNodes.iteritems():
39         for peer, info in peers.iteritems():
40             info.update(rating=round(info.get('rating', 0), 2))
41             _serialized.append({
42                 'stream': stream, 'peer': peer._asdict(), 'info': info
43             })
44     json.dump(_serialized, output, indent=4)
45 
46 
47 def json_deserialize_knownnodes(source):
48     """
49     Read JSON from source and make knownnodes dict
50     """
51     for node in json.load(source):
52         peer = node['peer']
53         peer['host'] = str(peer['host'])
54         knownNodes[node['stream']][state.Peer(**peer)] = node['info']
55 
56 
57 def pickle_deserialize_old_knownnodes(source):
58     """
59     Unpickle source and reorganize knownnodes dict if it's in old format
60     the old format was {Peer:lastseen, ...}
61     the new format is {Peer:{"lastseen":i, "rating":f}}
62     """
63     knownNodes = pickle.load(source)
64     for stream in knownNodes.keys():
65         for node, params in knownNodes[stream].items():
66             if isinstance(params, (float, int)):
67                 addKnownNode(stream, node, params)
68 
69 
70 def saveKnownNodes(dirName=None):
71     if dirName is None:
72         dirName = state.appdata
73     with knownNodesLock:
74         with open(os.path.join(dirName, 'knownnodes.dat'), 'wb') as output:
75             json_serialize_knownnodes(output)
76 
77 
78 def addKnownNode(stream, peer, lastseen=None, is_self=False):
79     knownNodes[stream][peer] = {
80         "lastseen": lastseen or time.time(),
81         "rating": 0,
82         "self": is_self,
83     }
84 
85 
86 def createDefaultKnownNodes():
87     for peer in DEFAULT_NODES:
88         addKnownNode(1, peer)
89     saveKnownNodes()
90 
91 
92 def readKnownNodes():
93     try:
94         with open(state.appdata + 'knownnodes.dat', 'rb') as source:
95             with knownNodesLock:
96                 try:
97                     json_deserialize_knownnodes(source)
98                 except ValueError:
99                     source.seek(0)
100                     pickle_deserialize_old_knownnodes(source)
101     except (IOError, OSError, KeyError):
102         logger.debug(
103             'Failed to read nodes from knownnodes.dat', exc_info=True)
104         createDefaultKnownNodes()
105 
106     config = BMConfigParser()
107     # if config.safeGetInt('bitmessagesettings', 'settingsversion') > 10:
108     #     sys.exit(
109     #         'Bitmessage cannot read future versions of the keys file'
110     #         ' (keys.dat). Run the newer version of Bitmessage.')
111 
112     # your own onion address, if setup
113     onionhostname = config.safeGet('bitmessagesettings', 'onionhostname')
114     if onionhostname and ".onion" in onionhostname:
115         onionport = config.safeGetInt('bitmessagesettings', 'onionport')
116         if onionport:
117             addKnownNode(1, state.Peer(onionhostname, onionport), is_self=True)
118 
119 
120 def increaseRating(peer):
121     increaseAmount = 0.1
122     maxRating = 1
123     with knownNodesLock:
124         for stream in knownNodes.keys():
125             try:
126                 knownNodes[stream][peer]["rating"] = min(
127                     knownNodes[stream][peer]["rating"] + increaseAmount,
128                     maxRating
129                 )
130             except KeyError:
131                 pass
132 
133 
134 def decreaseRating(peer):
135     decreaseAmount = 0.1
136     minRating = -1
137     with knownNodesLock:
138         for stream in knownNodes.keys():
139             try:
140                 knownNodes[stream][peer]["rating"] = max(
141                     knownNodes[stream][peer]["rating"] - decreaseAmount,
142                     minRating
143                 )
144             except KeyError:
145                 pass
146 
147 
148 def trimKnownNodes(recAddrStream=1):
149     if len(knownNodes[recAddrStream]) < \
150             BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
151         return
152     with knownNodesLock:
153         oldestList = sorted(
154             knownNodes[recAddrStream],
155             key=lambda x: x['lastseen']
156         )[:knownNodesTrimAmount]
157         for oldest in oldestList:
158             del knownNodes[recAddrStream][oldest]
159
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/knownnodes.py b/src/knownnodes.py
--- a/src/knownnodes.py
+++ b/src/knownnodes.py
@@ -98,7 +98,7 @@
                 except ValueError:
                     source.seek(0)
                     pickle_deserialize_old_knownnodes(source)
-    except (IOError, OSError, KeyError):
+    except (IOError, OSError, KeyError, EOFError):
         logger.debug(
             'Failed to read nodes from knownnodes.dat', exc_info=True)
         createDefaultKnownNodes()

{"golden_diff": "diff --git a/src/knownnodes.py b/src/knownnodes.py\n--- a/src/knownnodes.py\n+++ b/src/knownnodes.py\n@@ -98,7 +98,7 @@\n                 except ValueError:\n                     source.seek(0)\n                     pickle_deserialize_old_knownnodes(source)\n-    except (IOError, OSError, KeyError):\n+    except (IOError, OSError, KeyError, EOFError):\n         logger.debug(\n             'Failed to read nodes from knownnodes.dat', exc_info=True)\n         createDefaultKnownNodes()\n", "issue": "Crashing on Boot\n$ python src/bitmessagemain.py \r\nLoading existing config files from /home/.config/PyBitmessage/\r\n2018-08-05 13:19:02,170 - WARNING - Using default logger configuration\r\n2018-08-05 13:19:02,592 - CRITICAL - Unhandled exception\r\nTraceback (most recent call last):\r\n  File \"src/bitmessagemain.py\", line 507, in <module>\r\n  File \"src/bitmessagemain.py\", line 503, in main\r\n  File \"src/bitmessagemain.py\", line 276, in start\r\n  File \"PyBitmessage/src/knownnodes.py\", line 100, in readKnownNodes\r\n    pickle_deserialize_old_knownnodes(source)\r\n  File \"PyBitmessage/src/knownnodes.py\", line 63, in pickle_deserialize_old_knownnodes\r\n    knownNodes = pickle.load(source)\r\n  File \"/usr/lib/python2.7/pickle.py\", line 1384, in load\r\n    return Unpickler(file).load()\r\n  File \"/usr/lib/python2.7/pickle.py\", line 864, in load\r\n    dispatch[key](self)\r\n  File \"/usr/lib/python2.7/pickle.py\", line 886, in load_eof\r\n    raise EOFError\r\nEOFError\r\nCleaning up lockfile\r\n\n", "before_files": [{"content": "import json\nimport os\nimport pickle\n# import sys\nimport threading\nimport time\n\nimport state\nfrom bmconfigparser import BMConfigParser\nfrom debug import logger\n\nknownNodesLock = threading.Lock()\nknownNodes = {stream: {} for stream in range(1, 4)}\n\nknownNodesTrimAmount = 2000\n\n# forget a node after rating is this low\nknownNodesForgetRating = -0.5\n\nDEFAULT_NODES = (\n    state.Peer('5.45.99.75', 8444),\n    state.Peer('75.167.159.54', 8444),\n    state.Peer('95.165.168.168', 8444),\n    state.Peer('85.180.139.241', 8444),\n    state.Peer('158.222.217.190', 8080),\n    state.Peer('178.62.12.187', 8448),\n    state.Peer('24.188.198.204', 8111),\n    state.Peer('109.147.204.113', 1195),\n    state.Peer('178.11.46.221', 8444)\n)\n\n\ndef json_serialize_knownnodes(output):\n    \"\"\"\n    Reorganize knownnodes dict and write it as JSON to output\n    \"\"\"\n    _serialized = []\n    for stream, peers in knownNodes.iteritems():\n        for peer, info in peers.iteritems():\n            info.update(rating=round(info.get('rating', 0), 2))\n            _serialized.append({\n                'stream': stream, 'peer': peer._asdict(), 'info': info\n            })\n    json.dump(_serialized, output, indent=4)\n\n\ndef json_deserialize_knownnodes(source):\n    \"\"\"\n    Read JSON from source and make knownnodes dict\n    \"\"\"\n    for node in json.load(source):\n        peer = node['peer']\n        peer['host'] = str(peer['host'])\n        knownNodes[node['stream']][state.Peer(**peer)] = node['info']\n\n\ndef pickle_deserialize_old_knownnodes(source):\n    \"\"\"\n    Unpickle source and reorganize knownnodes dict if it's in old format\n    the old format was {Peer:lastseen, ...}\n    the new format is {Peer:{\"lastseen\":i, \"rating\":f}}\n    \"\"\"\n    knownNodes = pickle.load(source)\n    for stream in knownNodes.keys():\n        for node, params in knownNodes[stream].items():\n            if isinstance(params, (float, int)):\n                addKnownNode(stream, node, params)\n\n\ndef saveKnownNodes(dirName=None):\n    if dirName is None:\n        dirName = state.appdata\n    with knownNodesLock:\n        with open(os.path.join(dirName, 'knownnodes.dat'), 'wb') as output:\n            json_serialize_knownnodes(output)\n\n\ndef addKnownNode(stream, peer, lastseen=None, is_self=False):\n    knownNodes[stream][peer] = {\n        \"lastseen\": lastseen or time.time(),\n        \"rating\": 0,\n        \"self\": is_self,\n    }\n\n\ndef createDefaultKnownNodes():\n    for peer in DEFAULT_NODES:\n        addKnownNode(1, peer)\n    saveKnownNodes()\n\n\ndef readKnownNodes():\n    try:\n        with open(state.appdata + 'knownnodes.dat', 'rb') as source:\n            with knownNodesLock:\n                try:\n                    json_deserialize_knownnodes(source)\n                except ValueError:\n                    source.seek(0)\n                    pickle_deserialize_old_knownnodes(source)\n    except (IOError, OSError, KeyError):\n        logger.debug(\n            'Failed to read nodes from knownnodes.dat', exc_info=True)\n        createDefaultKnownNodes()\n\n    config = BMConfigParser()\n    # if config.safeGetInt('bitmessagesettings', 'settingsversion') > 10:\n    #     sys.exit(\n    #         'Bitmessage cannot read future versions of the keys file'\n    #         ' (keys.dat). Run the newer version of Bitmessage.')\n\n    # your own onion address, if setup\n    onionhostname = config.safeGet('bitmessagesettings', 'onionhostname')\n    if onionhostname and \".onion\" in onionhostname:\n        onionport = config.safeGetInt('bitmessagesettings', 'onionport')\n        if onionport:\n            addKnownNode(1, state.Peer(onionhostname, onionport), is_self=True)\n\n\ndef increaseRating(peer):\n    increaseAmount = 0.1\n    maxRating = 1\n    with knownNodesLock:\n        for stream in knownNodes.keys():\n            try:\n                knownNodes[stream][peer][\"rating\"] = min(\n                    knownNodes[stream][peer][\"rating\"] + increaseAmount,\n                    maxRating\n                )\n            except KeyError:\n                pass\n\n\ndef decreaseRating(peer):\n    decreaseAmount = 0.1\n    minRating = -1\n    with knownNodesLock:\n        for stream in knownNodes.keys():\n            try:\n                knownNodes[stream][peer][\"rating\"] = max(\n                    knownNodes[stream][peer][\"rating\"] - decreaseAmount,\n                    minRating\n                )\n            except KeyError:\n                pass\n\n\ndef trimKnownNodes(recAddrStream=1):\n    if len(knownNodes[recAddrStream]) < \\\n            BMConfigParser().safeGetInt(\"knownnodes\", \"maxnodes\"):\n        return\n    with knownNodesLock:\n        oldestList = sorted(\n            knownNodes[recAddrStream],\n            key=lambda x: x['lastseen']\n        )[:knownNodesTrimAmount]\n        for oldest in oldestList:\n            del knownNodes[recAddrStream][oldest]\n", "path": "src/knownnodes.py"}], "after_files": [{"content": "import json\nimport os\nimport pickle\n# import sys\nimport threading\nimport time\n\nimport state\nfrom bmconfigparser import BMConfigParser\nfrom debug import logger\n\nknownNodesLock = threading.Lock()\nknownNodes = {stream: {} for stream in range(1, 4)}\n\nknownNodesTrimAmount = 2000\n\n# forget a node after rating is this low\nknownNodesForgetRating = -0.5\n\nDEFAULT_NODES = (\n    state.Peer('5.45.99.75', 8444),\n    state.Peer('75.167.159.54', 8444),\n    state.Peer('95.165.168.168', 8444),\n    state.Peer('85.180.139.241', 8444),\n    state.Peer('158.222.217.190', 8080),\n    state.Peer('178.62.12.187', 8448),\n    state.Peer('24.188.198.204', 8111),\n    state.Peer('109.147.204.113', 1195),\n    state.Peer('178.11.46.221', 8444)\n)\n\n\ndef json_serialize_knownnodes(output):\n    \"\"\"\n    Reorganize knownnodes dict and write it as JSON to output\n    \"\"\"\n    _serialized = []\n    for stream, peers in knownNodes.iteritems():\n        for peer, info in peers.iteritems():\n            info.update(rating=round(info.get('rating', 0), 2))\n            _serialized.append({\n                'stream': stream, 'peer': peer._asdict(), 'info': info\n            })\n    json.dump(_serialized, output, indent=4)\n\n\ndef json_deserialize_knownnodes(source):\n    \"\"\"\n    Read JSON from source and make knownnodes dict\n    \"\"\"\n    for node in json.load(source):\n        peer = node['peer']\n        peer['host'] = str(peer['host'])\n        knownNodes[node['stream']][state.Peer(**peer)] = node['info']\n\n\ndef pickle_deserialize_old_knownnodes(source):\n    \"\"\"\n    Unpickle source and reorganize knownnodes dict if it's in old format\n    the old format was {Peer:lastseen, ...}\n    the new format is {Peer:{\"lastseen\":i, \"rating\":f}}\n    \"\"\"\n    knownNodes = pickle.load(source)\n    for stream in knownNodes.keys():\n        for node, params in knownNodes[stream].items():\n            if isinstance(params, (float, int)):\n                addKnownNode(stream, node, params)\n\n\ndef saveKnownNodes(dirName=None):\n    if dirName is None:\n        dirName = state.appdata\n    with knownNodesLock:\n        with open(os.path.join(dirName, 'knownnodes.dat'), 'wb') as output:\n            json_serialize_knownnodes(output)\n\n\ndef addKnownNode(stream, peer, lastseen=None, is_self=False):\n    knownNodes[stream][peer] = {\n        \"lastseen\": lastseen or time.time(),\n        \"rating\": 0,\n        \"self\": is_self,\n    }\n\n\ndef createDefaultKnownNodes():\n    for peer in DEFAULT_NODES:\n        addKnownNode(1, peer)\n    saveKnownNodes()\n\n\ndef readKnownNodes():\n    try:\n        with open(state.appdata + 'knownnodes.dat', 'rb') as source:\n            with knownNodesLock:\n                try:\n                    json_deserialize_knownnodes(source)\n                except ValueError:\n                    source.seek(0)\n                    pickle_deserialize_old_knownnodes(source)\n    except (IOError, OSError, KeyError, EOFError):\n        logger.debug(\n            'Failed to read nodes from knownnodes.dat', exc_info=True)\n        createDefaultKnownNodes()\n\n    config = BMConfigParser()\n    # if config.safeGetInt('bitmessagesettings', 'settingsversion') > 10:\n    #     sys.exit(\n    #         'Bitmessage cannot read future versions of the keys file'\n    #         ' (keys.dat). Run the newer version of Bitmessage.')\n\n    # your own onion address, if setup\n    onionhostname = config.safeGet('bitmessagesettings', 'onionhostname')\n    if onionhostname and \".onion\" in onionhostname:\n        onionport = config.safeGetInt('bitmessagesettings', 'onionport')\n        if onionport:\n            addKnownNode(1, state.Peer(onionhostname, onionport), is_self=True)\n\n\ndef increaseRating(peer):\n    increaseAmount = 0.1\n    maxRating = 1\n    with knownNodesLock:\n        for stream in knownNodes.keys():\n            try:\n                knownNodes[stream][peer][\"rating\"] = min(\n                    knownNodes[stream][peer][\"rating\"] + increaseAmount,\n                    maxRating\n                )\n            except KeyError:\n                pass\n\n\ndef decreaseRating(peer):\n    decreaseAmount = 0.1\n    minRating = -1\n    with knownNodesLock:\n        for stream in knownNodes.keys():\n            try:\n                knownNodes[stream][peer][\"rating\"] = max(\n                    knownNodes[stream][peer][\"rating\"] - decreaseAmount,\n                    minRating\n                )\n            except KeyError:\n                pass\n\n\ndef trimKnownNodes(recAddrStream=1):\n    if len(knownNodes[recAddrStream]) < \\\n            BMConfigParser().safeGetInt(\"knownnodes\", \"maxnodes\"):\n        return\n    with knownNodesLock:\n        oldestList = sorted(\n            knownNodes[recAddrStream],\n            key=lambda x: x['lastseen']\n        )[:knownNodesTrimAmount]\n        for oldest in oldestList:\n            del knownNodes[recAddrStream][oldest]\n", "path": "src/knownnodes.py"}]}