Skip to content

Commit

Permalink
fix: Force new instance of AsyncHTTPClient
Browse files Browse the repository at this point in the history
* Without new instance it will mess up JupyterHub single user extension's client

Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Apr 10, 2024
1 parent 6a985fc commit 3f3ebd8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions jupyter_power_usage/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ class ElectrictyMapsHandler(JupyterHandler):
The purpose of this proxy is to provide authentication to the API requests.
"""

client = AsyncHTTPClient()
# Force a new instance to not to mess up with other instances that might exist in
# JupyterHub or other Jupyter related stacks
#
# Without this we noticed that JupyterHub will fail to spawn instances when internal
# TLS is on. The reason is that this new instantiation will override the already
# existing instance in single user extension that has SSL context configured. So
# we lose SSL context and hence cert verification will fail eventually failing spawn.
client = AsyncHTTPClient(force_instance=True)

def initialize(self):
# Get access token(s) from config
Expand All @@ -119,7 +126,7 @@ def initialize(self):

@web.authenticated
async def get(self, path):
"""Return emission factor data from electticity maps"""
"""Return emission factor data from electricity maps"""
try:
query = self.request.query_arguments
params = {key: query[key][0].decode() for key in query}
Expand Down

0 comments on commit 3f3ebd8

Please sign in to comment.