Unverified Commit 4185025d authored by John G G's avatar John G G Committed by GitHub

Merge branch 'master' into timeouts

parents 227d8e24 1b7dccd7
......@@ -17,7 +17,6 @@ from .typedefs import HTTPResponse
from .typedefs import JrpcRequest
from .typedefs import JrpcResponse
from .typedefs import WebApp
from .async_stats import fmt_timings
logger = structlog.get_logger(__name__)
......@@ -34,6 +33,7 @@ class Default(dict):
def setup_error_handlers(app: WebApp) -> WebApp:
# pylint: disable=unused-variable
@app.exception(sanic.exceptions.RequestTimeout)
def handle_request_timeout_errors(request: HTTPRequest,
exception: sanic.exceptions.RequestTimeout) -> Optional[HTTPResponse]:
......@@ -43,6 +43,7 @@ def setup_error_handlers(app: WebApp) -> WebApp:
jrpc_request=request.jsonrpc,
exception=exception).to_sanic_response()
@app.exception(sanic.exceptions.ServiceUnavailable)
def handle_response_timeout_errors(request: HTTPRequest,
exception: sanic.exceptions.ServiceUnavailable) -> Optional[HTTPResponse]:
......@@ -206,30 +207,6 @@ class JussiInteralError(Exception):
return base_error
def timings(self) -> Optional[dict]:
try:
if self.http_request.is_single_jrpc:
request_timings = fmt_timings(self.http_request.timings)
jsonrpc_timings = fmt_timings(self.http_request.jsonrpc.timings)
return {
'request_timings': request_timings,
'jsonrpc_timings': jsonrpc_timings
}
elif self.http_request.is_batch_jrpc:
request_timings = fmt_timings(self.http_request.timings)
jsonrpc_timings = []
for r in self.http_request.jsonrpc:
jsonrpc_timings.extend(fmt_timings(r.timings))
return {
'request_timings': request_timings,
'jsonrpc_timings': jsonrpc_timings
}
else:
return None
except Exception as e:
return None
def log(self) -> None:
if self.log_traceback and self.exception:
self.logger.error(self.format_message(), **self.to_dict(),
......@@ -318,7 +295,7 @@ class ResponseTimeoutError(JsonRpcError):
logger.info('error adding timing data to RequestTimeoutError', e=e)
return data
class UpstreamResponseError(JsonRpcError):
code = 1100
message = 'Upstream response error'
......
# -*- coding: utf-8 -*-
import asyncio
from time import perf_counter
import structlog
# pylint: disable=no-name-in-module
from websockets import WebSocketClientProtocol as WSConn
......@@ -266,26 +264,17 @@ class Pool:
async def _get_new_connection(self) -> WSConn:
# First connection attempt on this pool.
logger.debug('spawning new ws conn')
start = perf_counter()
conn = await websockets_connect(self._connect_url, loop=self._loop,
return await websockets_connect(self._connect_url, loop=self._loop,
**self._connect_kwargs)
elapsed = perf_counter() - start
logger.info('new ws conn', elapsed=elapsed)
return conn
async def acquire(self, timeout: int=None) -> PoolConnectionProxy:
async def _acquire_impl(timeout=None) -> PoolConnectionProxy:
start = perf_counter()
ch = await self._queue.get() # type: PoolConnectionHolder
self._queue.task_done()
try:
proxy = await ch.acquire() # type: # type: PoolConnectionProxy
elapsed = perf_counter() - start
if elapsed > 1:
logger.info('acquire ws conn', elapsed=elapsed)
except Exception:
self._queue.put_nowait(ch)
raise
else:
# Record the timeout, as we will apply it by default
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment