Skip to content

Commit

Permalink
Merge pull request #3 from cabernetwork/dev
Browse files Browse the repository at this point in the history
Fix HTTP socket timeout issues
  • Loading branch information
rocky4546 authored Sep 23, 2021
2 parents e972780 + b356d54 commit ec6d484
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/common/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def handle_url_except(f=None, timeout=None):
return functools.partial(handle_url_except, timeout=timeout)
def wrapper_func(self, *args, **kwargs):
ex_save = ''
i = 3
i = 2
while i > 0:
i -= 1
try:
Expand Down
2 changes: 1 addition & 1 deletion lib/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import lib.common.exceptions as exceptions

VERSION = '0.9.3.9'
VERSION = '0.9.3.10'
CABERNET_URL = 'https://github.com/cabernetwork/cabernet'
CABERNET_NAMESPACE = 'Cabernet'
DEFAULT_USER_AGENT = 'Mozilla/5.0'
Expand Down
3 changes: 1 addition & 2 deletions lib/streams/internal_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, _plugins, _hdhr_queue):
self.out_queue = Queue(maxsize=3)
self.terminate_queue = None
self.tc_match = re.compile( r'^.+[^\d]+(\d*)\.ts' )
self.idle_counter = 0
self.idle_counter = 30

def terminate(self, *args):
try:
Expand Down Expand Up @@ -103,7 +103,6 @@ def stream(self, _channel_dict, _wfile, _terminate_queue):

self.wfile = _wfile
self.terminate_queue = _terminate_queue

while True:
try:
self.check_termination()
Expand Down
10 changes: 5 additions & 5 deletions lib/streams/m3u8_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def __init__(self, _config, _channel_dict):
self.key_list = {}
self.start()

@handle_url_except(timeout=1.0)
@handle_url_except()
def get_uri_data(self, _uri):
header = {'User-agent': utils.DEFAULT_USER_AGENT}
req = urllib.request.Request(_uri, headers=header)
with urllib.request.urlopen(req, timeout=1.0) as resp:
with urllib.request.urlopen(req, timeout=5.0) as resp:
x = resp.read()
return x

Expand Down Expand Up @@ -384,13 +384,13 @@ def remove_from_stream_queue(self, _playlist):

def start(_config, _plugins, _m3u8_queue, _data_queue, _channel_dict, extra=None):
"""
All items in this process must handle a socket timeout of 1.0
All items in this process must handle a socket timeout of 5.0
"""
global IN_QUEUE
global STREAM_QUEUE
global OUT_QUEUE
global TERMINATE_REQUESTED
socket.setdefaulttimeout(1.0)
socket.setdefaulttimeout(5.0)
IN_QUEUE = _m3u8_queue
STREAM_QUEUE = Queue()
OUT_QUEUE = _data_queue
Expand All @@ -407,5 +407,5 @@ def start(_config, _plugins, _m3u8_queue, _data_queue, _channel_dict, extra=None
except (KeyboardInterrupt, EOFError):
TERMINATE_REQUESTED = True
STREAM_QUEUE.put({'uri': 'terminate'})
time.sleep(1.0)
time.sleep(5.0)
sys.exit()

0 comments on commit ec6d484

Please sign in to comment.