Skip to content

Commit

Permalink
wrap error (#311)
Browse files Browse the repository at this point in the history
Wrap error from interrupt streaming
  • Loading branch information
xinlili-statsig authored Sep 11, 2024
1 parent 82189f2 commit 8360c54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Upload base benchmark score
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: python-perf
path: /tmp/perf/python_perf_score.txt
Expand Down
24 changes: 20 additions & 4 deletions statsig/grpc_websocket_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ def _start_listening(self, dcs_data_cb: Callable, since_time=0, timeout=None):
def _listen_for_dcs(self, since_time=0):
try:
if self.dcs_stream is not None:
initial_metadata = self.dcs_stream.initial_metadata()
for metadata in initial_metadata:
if metadata.key == "x-sfp-hostname":
self.server_host_name = metadata.value
self.get_stream_metadata()
for response in self.dcs_stream:
if self.retrying:
self.retrying = False
Expand Down Expand Up @@ -279,6 +276,25 @@ def on_reconnect(self):
if self._backup_callbacks:
self._backup_callbacks.cancel_backup()

def get_stream_metadata(self):
try:
if self.dcs_stream is not None:
initial_metadata = self.dcs_stream.initial_metadata()
for metadata in initial_metadata:
if metadata.key == "x-sfp-hostname":
self.server_host_name = metadata.value
except Exception as error:
self.error_boundary.log_exception(
"grpcWebSocket: connection error",
error,
{
"retryAttempt": self.retry_limit - self.remaining_retry,
"hostName": socket.gethostname(),
"sfpHostName": self.server_host_name,
},
True,
)

def shutdown(self) -> None:
self.is_shutting_down = True
if self._backup_callbacks:
Expand Down
1 change: 0 additions & 1 deletion statsig/statsig_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(
self.http_worker: IStatsigNetworkWorker = defaultHttpWorker
for endpoint, config in options.proxy_configs.items():
protocol = config.protocol
worker = defaultHttpWorker
if protocol == NetworkProtocol.GRPC:
self.load_grpc_worker(endpoint, config)
elif protocol == NetworkProtocol.GRPC_WEBSOCKET:
Expand Down

0 comments on commit 8360c54

Please sign in to comment.