handle secure errors in readOnce (secure) (#397)

* handle secure errors in readOnce(secure)

* small synthax fix

* fix mistake in readOnce's isNil
This commit is contained in:
Giovanni Petrantoni 2020-10-19 14:13:14 +09:00 committed by GitHub
parent bd70515087
commit 32623b930e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -120,10 +120,23 @@ method readOnce*(s: SecureConn,
doAssert(nbytes > 0, "nbytes must be positive integer") doAssert(nbytes > 0, "nbytes must be positive integer")
if s.buf.data().len() == 0: if s.buf.data().len() == 0:
let buf = await s.readMessage() let (buf, err) = try:
(await s.readMessage(), nil)
except CatchableError as exc:
(@[], exc)
if not isNil(err):
warn "error while reading message from secure connection, closing.", error=err.name,
message=err.msg,
connection=s
await s.close()
raise err
s.activity = true s.activity = true
if buf.len == 0: if buf.len == 0:
raise newLPStreamIncompleteError() raise newLPStreamIncompleteError()
s.buf.add(buf) s.buf.add(buf)
var p = cast[ptr UncheckedArray[byte]](pbytes) var p = cast[ptr UncheckedArray[byte]](pbytes)