Skip to content

Commit c99db48

Browse files
committed
fix: ignore streaming pong messages
1 parent 9da7cbd commit c99db48

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎fbclient/streaming.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ def _on_message(self, wsapp: websocket.WebSocketApp, msg):
302302
log.trace('Streaming WebSocket data: %s' % msg) # type: ignore
303303
try:
304304
all_data = json.loads(msg)
305+
if all_data.get('messageType') == 'pong':
306+
return
305307
if not valide_all_data(all_data):
306308
raise ValueError('invalid streaming data')
307309
if not self._on_process_data(all_data['data']) and self.__wsapp:

‎tests/test_runtime_safety.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import json
23
import queue
34
import threading
45
from time import sleep
@@ -76,6 +77,28 @@ def test_repeatable_task_can_be_joined_cleanly():
7677
assert not task.is_alive()
7778

7879

80+
def test_streaming_ignores_pong_control_messages():
81+
config = Config(FAKE_ENV_SECRET,
82+
event_url=FAKE_URL,
83+
streaming_url=FAKE_URL,
84+
offline=True)
85+
storage = InMemoryDataStorage()
86+
status = DataUpdateStatusProviderImpl(storage)
87+
streaming = Streaming(config, NoticeBroadcater(), status, threading.Event())
88+
89+
class FakeWebSocket:
90+
def close(self, **_kwargs):
91+
raise AssertionError("pong must not close the WebSocket")
92+
93+
streaming._on_message(FakeWebSocket(), json.dumps({
94+
"messageType": "pong",
95+
"data": {},
96+
}))
97+
98+
assert status.current_state.state_type == StateType.INITIALIZING
99+
streaming.stop()
100+
101+
79102
def test_notice_broadcaster_is_safe_during_listener_churn():
80103
broadcaster = NoticeBroadcater()
81104
callback_count = [0]

0 commit comments

Comments
 (0)