Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions SRT/netfunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,43 +97,41 @@ def _wait_until_complete(self, key: str, nwait: str) -> str:
NetFunnel이 완료될 때까지 대기합니다.
"""

params = {
"opcode": self.OP_CODE["chkEnter"],
"key": key,
"nfid": "0",
"prefix": f"NetFunnel.gRtype={self.OP_CODE['chkEnter']};",
"ttl": 1,
"sid": "service_1",
"aid": "act_10",
"js": "true",
self._get_timestamp_for_netfunnel(): "",
}

try:
resp = self.session.get(
self.NETFUNNEL_URL,
params=params,
)
except Exception as e:
raise SRTNetFunnelError(e) from e

netfunnel_resp = NetFunnelResponse.parse(resp.text)

nwait_ = netfunnel_resp.get("nwait")
key_ = netfunnel_resp.get("key")
if key_ is None:
raise SRTNetFunnelError("NetFunnel key not found in response")

if nwait_ and nwait_ != "0":
print(f"대기인원: {nwait_}명")

# 1 sec
# TODO: find how to calculate the re-try interval
time.sleep(1)

return self._wait_until_complete(key_, nwait_)
else:
return key_
while True:
params = {
"opcode": self.OP_CODE["chkEnter"],
"key": key,
"nfid": "0",
"prefix": f"NetFunnel.gRtype={self.OP_CODE['chkEnter']};",
"ttl": 1,
"sid": "service_1",
"aid": "act_10",
"js": "true",
self._get_timestamp_for_netfunnel(): "",
}

try:
resp = self.session.get(
self.NETFUNNEL_URL,
params=params,
)
Comment on lines +114 to +117

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Under high-traffic conditions (when NetFunnel is typically active), the server is more likely to experience high load, leading to dropped connections or extremely slow responses. Since requests.get has no default timeout, the call can hang indefinitely, causing the application to freeze. Adding an explicit timeout parameter prevents this.

Suggested change
resp = self.session.get(
self.NETFUNNEL_URL,
params=params,
)
resp = self.session.get(
self.NETFUNNEL_URL,
params=params,
timeout=10,
)

except Exception as e:
raise SRTNetFunnelError(e) from e

netfunnel_resp = NetFunnelResponse.parse(resp.text)

nwait_ = netfunnel_resp.get("nwait")
key_ = netfunnel_resp.get("key")
if key_ is None:
raise SRTNetFunnelError("NetFunnel key not found in response")

if nwait_ and nwait_ != "0":
print(f"대기인원: {nwait_}명")
# TODO: find how to calculate the re-try interval
time.sleep(1)
key = key_
else:
return key_

def _set_complete(self, key: str):
"""
Expand Down
Loading