mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
pyln: Fix an issue with the LightningConnection short-reading
We may end up with a short read, that is not empty, when a message gets fragmented during transport, so we need to loop until we either reach the full size or we have an empty read indicating a dropped connection. Changelog-None
This commit is contained in:
parent
280b49a677
commit
d7cd3e1cb5
1 changed files with 14 additions and 6 deletions
|
@ -236,13 +236,21 @@ class LightningConnection(object):
|
|||
length, = struct.unpack("!H", length)
|
||||
self.rn += 1
|
||||
|
||||
mc = self.connection.recv(length + 16)
|
||||
if len(mc) < length + 16:
|
||||
raise ValueError(
|
||||
"Short read reading the message: {} != {}".format(
|
||||
length + 16, len(lc)
|
||||
# Large messages may be split into multiple packets:
|
||||
mc = b''
|
||||
toread = length + 16
|
||||
while len(mc) < length + 16:
|
||||
d = self.connection.recv(toread)
|
||||
if len(d) == 0:
|
||||
# Not making progress anymore
|
||||
raise ValueError(
|
||||
"Short read reading the message: {} != {}".format(
|
||||
length + 16, len(mc)
|
||||
)
|
||||
)
|
||||
)
|
||||
mc += d
|
||||
toread -= len(d)
|
||||
|
||||
m = decryptWithAD(self.rk, self.nonce(self.rn), b'', mc)
|
||||
self.rn += 1
|
||||
assert(self.rn % 2 == 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue