WS: add timeout to handleRequest (#796)
This commit is contained in:
parent
711609057c
commit
c43aacdc81
|
@ -35,14 +35,18 @@ logScope:
|
|||
export transport, websock, results
|
||||
|
||||
const
|
||||
WsTransportTrackerName* = "libp2p.wstransport"
|
||||
|
||||
DefaultHeadersTimeout = 3.seconds
|
||||
|
||||
type
|
||||
WsStream = ref object of Connection
|
||||
session: WSSession
|
||||
|
||||
method initStream*(s: WsStream) =
|
||||
if s.objName.len == 0:
|
||||
s.objName = "WsStream"
|
||||
|
||||
procCall Connection(s).initStream()
|
||||
|
||||
proc new*(T: type WsStream,
|
||||
session: WSSession,
|
||||
dir: Direction,
|
||||
|
@ -256,7 +260,7 @@ method accept*(self: WsTransport): Future[Connection] {.async, gcsafe.} =
|
|||
|
||||
try:
|
||||
let
|
||||
wstransp = await self.wsserver.handleRequest(req)
|
||||
wstransp = await self.wsserver.handleRequest(req).wait(self.handshakeTimeout)
|
||||
isSecure = self.httpservers[index].secure
|
||||
|
||||
return await self.connHandler(wstransp, isSecure, Direction.In)
|
||||
|
@ -273,6 +277,8 @@ method accept*(self: WsTransport): Future[Connection] {.async, gcsafe.} =
|
|||
debug "AsyncStream Error", exc = exc.msg
|
||||
except TransportTooManyError as exc:
|
||||
debug "Too many files opened", exc = exc.msg
|
||||
except AsyncTimeoutError as exc:
|
||||
debug "Timed out", exc = exc.msg
|
||||
except TransportUseClosedError as exc:
|
||||
debug "Server was closed", exc = exc.msg
|
||||
raise newTransportClosedError(exc)
|
||||
|
|
Loading…
Reference in New Issue