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