Skip to content

Commit 380e0cc

Browse files
authored
Catch KeyError within Threadless executors (#1396)
1 parent 7824847 commit 380e0cc

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ build
3636

3737
pyreverse.png
3838
profile.svg
39-
4039
*-pre-push
4140
jaxl-api-credentials*.json

.vscode/settings.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,19 @@
4141
"python.linting.flake8Args": ["--config", ".flake8"],
4242
"python.linting.mypyEnabled": true,
4343
"python.formatting.provider": "autopep8",
44-
"autoDocstring.docstringFormat": "sphinx"
44+
"autoDocstring.docstringFormat": "sphinx",
45+
"emeraldwalk.runonsave": {
46+
"commands": [
47+
{
48+
"match": "\\.py$",
49+
"isAsync": false,
50+
"cmd": "./.venv/bin/autoflake --in-place --remove-all-unused-imports \"${file}\""
51+
},
52+
{
53+
"match": "\\.py$",
54+
"isAsync": false,
55+
"cmd": "./.venv/bin/isort \"${file}\""
56+
}
57+
]
58+
}
4559
}

proxy/core/work/threadless.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,21 @@ async def _update_work_events(self, work_id: int) -> None:
191191
#
192192
# TODO: Also remove offending work from pool to avoid spin loop.
193193
elif fileno != -1:
194-
self.selector.register(fileno, events=mask, data=work_id)
195-
self.registered_events_by_work_ids[work_id][fileno] = mask
196-
logger.debug(
197-
'fd#{0} registered for mask#{1} by work#{2}'.format(
198-
fileno, mask, work_id,
199-
),
200-
)
194+
try:
195+
self.selector.register(fileno, events=mask, data=work_id)
196+
self.registered_events_by_work_ids[work_id][fileno] = mask
197+
logger.debug(
198+
'fd#{0} registered for mask#{1} by work#{2}'.format(
199+
fileno,
200+
mask,
201+
work_id,
202+
),
203+
)
204+
except KeyError as exc:
205+
logger.warning(
206+
'KeyError when trying to register fd#{0}'.format(fileno),
207+
exc_info=exc,
208+
)
201209

202210
async def _update_conn_pool_events(self) -> None:
203211
if not self._upstream_conn_pool:

proxy/http/parser/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ def is_connection_upgrade(self) -> bool:
216216
self.has_header(b'Connection') and \
217217
self.has_header(b'Upgrade')
218218

219+
@property
220+
def is_websocket_upgrade(self) -> bool:
221+
return (
222+
self.is_connection_upgrade
223+
and self.header(b'upgrade').lower() == b'websocket'
224+
)
225+
219226
@property
220227
def is_https_tunnel(self) -> bool:
221228
"""Returns true for HTTPS CONNECT tunnel request."""

0 commit comments

Comments
 (0)