Skip to content

Commit 2b1e111

Browse files
authored
signalling: Stop logging errors on WS connection closing (#239)
1 parent cc0c681 commit 2b1e111

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

getstream/video/rtc/signaling.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import asyncio
2-
import threading
3-
import websocket
42
import logging
3+
import threading
54
import time
6-
from typing import TYPE_CHECKING, Any, Callable, Awaitable, Optional, Set
5+
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Optional, Set
6+
7+
import websocket
78

89
from getstream.common import telemetry
910
from getstream.utils import StreamAsyncIOEventEmitter
11+
1012
from .pb.stream.video.sfu.event import events_pb2
1113

1214
if TYPE_CHECKING:
@@ -196,7 +198,16 @@ def _on_message(self, ws, message):
196198

197199
def _on_error(self, ws, error):
198200
"""Handle WebSocket error."""
199-
logger.error(f"WebSocket error: {str(error)}")
201+
if (
202+
isinstance(error, websocket.ABNF)
203+
and error.opcode == websocket.ABNF.OPCODE_CLOSE
204+
):
205+
# For some reason, websockets lib propagates closing frame as an error.
206+
# Simply log a debug here if that happens.
207+
logger.debug(f"WebSocket closed by server: {error}")
208+
else:
209+
logger.error(f"WebSocket error: {error}")
210+
200211
if not self.first_message_event.is_set():
201212
# Create an error event
202213
error_event = events_pb2.SfuEvent()

0 commit comments

Comments
 (0)