diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 26d53fa25..707141882 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -37,13 +37,13 @@ def _archiveorg(url): def archive_url(url): - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url) + gevent.spawn(_archiveorg, url) if url.startswith('https://twitter.com/'): url = url.replace('https://twitter.com/', 'https://nitter.net/') - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url) + gevent.spawn(_archiveorg, url) if url.startswith('https://instagram.com/'): url = url.replace('https://instagram.com/', 'https://imginn.com/') - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url) + gevent.spawn(_archiveorg, url) def snappy_report(post, reason): report = Report(post_id=post.id, user_id=SNAPPY_ID, reason=reason) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index bec572487..bb2ab08fe 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -239,7 +239,7 @@ def push_notif(uids, title, body, url_or_comment): subscriptions = g.db.query(PushSubscription.subscription_json).filter(PushSubscription.user_id.in_(uids)).all() subscriptions = [x[0] for x in subscriptions] - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _push_notif_thread, subscriptions, title, body, url) + gevent.spawn(_push_notif_thread, subscriptions, title, body, url) def _push_notif_thread(subscriptions, title, body, url): diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index ba6e0fc07..9d2ee62d7 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -1157,5 +1157,3 @@ from sqlalchemy.orm import scoped_session, sessionmaker engine = create_engine(environ.get("DATABASE_URL").strip(), connect_args={"options": "-c statement_timeout=5000 -c idle_in_transaction_session_timeout=40000"}) db_session = scoped_session(sessionmaker(bind=engine, autoflush=False)) - -GEVENT_GENERIC_TIMEOUT = 10 diff --git a/files/helpers/media.py b/files/helpers/media.py index 719155972..c12716cde 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -150,7 +150,7 @@ def process_video(file, v): if extension != '.mp4': new = new.replace(extension, '.mp4') copyfile(old, new) - gevent.with_timeout(35, convert_to_mp4, old, new) + gevent.spawn(convert_to_mp4, old, new) else: try: subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new]) diff --git a/files/routes/__init__.py b/files/routes/__init__.py index 62f5d4af1..a2a3f1df8 100644 --- a/files/routes/__init__.py +++ b/files/routes/__init__.py @@ -54,5 +54,5 @@ if FEATURES['PING_GROUPS']: if IS_LOCALHOST: from files.helpers.cron import cron_fn print('Starting cron tasks!', flush=True) - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, cron_fn, True, False) + gevent.spawn(cron_fn, True, False) print('Cron tasks Finished!', flush=True) diff --git a/files/routes/comments.py b/files/routes/comments.py index 3c243abf4..946aa3917 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -57,7 +57,7 @@ def post_pid_comment_cid(cid, v, pid=None, anything=None, sub=None): post = NOTIFICATION_THREAD if v and request.values.get("read"): - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _mark_comment_as_read, comment.id, v.id) + gevent.spawn(_mark_comment_as_read, comment.id, v.id) post = get_post(post, v=v) diff --git a/files/routes/posts.py b/files/routes/posts.py index fcc0551c9..90278fd5b 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -103,7 +103,7 @@ def post_id(pid, v, anything=None, sub=None): if not g.is_api_or_xhr and p.over_18 and not (v and v.over_18) and session.get('over_18_cookies', 0) < int(time.time()): return render_template("errors/nsfw.html", v=v) - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_post_view, pid) + gevent.spawn(_add_post_view, pid) if p.new: defaultsortingcomments = 'new' elif v: defaultsortingcomments = v.defaultsortingcomments @@ -676,7 +676,7 @@ def submit_post(v, sub=None): g.db.flush() #Necessary, do NOT remove if not p.thumburl and p.url and p.domain != SITE: - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, thumbnail_thread, p.url, p.id) + gevent.spawn(thumbnail_thread, p.url, p.id) if v.client: return p.json else: @@ -920,6 +920,7 @@ extensions = IMAGE_FORMATS + VIDEO_FORMATS + AUDIO_FORMATS @limiter.limit("3/minute", deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required def get_post_title(v): + POST_TITLE_TIMEOUT = 5 url = request.values.get("url") if not url or '\\' in url: abort(400) url = url.strip() @@ -930,7 +931,7 @@ def get_post_title(v): abort(400) try: - x = gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, requests.get, url, headers=HEADERS, proxies=proxies) + x = gevent.with_timeout(POST_TITLE_TIMEOUT, requests.get, url, headers=HEADERS, timeout=POST_TITLE_TIMEOUT, proxies=proxies) except: abort(400) content_type = x.headers.get("Content-Type") diff --git a/files/routes/settings.py b/files/routes/settings.py index 941582d61..82fb3fed6 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -877,7 +877,7 @@ def settings_song_change(v): if duration > 15: return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!") - gevent.with_timeout(60, _change_song_youtube, v.id, id) + gevent.spawn(_change_song_youtube, v.id, id) return redirect("/settings/personal?msg=Profile Anthem successfully updated. Wait 5 minutes for the change to take effect.") diff --git a/files/routes/users.py b/files/routes/users.py index de5601c35..e0470af4f 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -951,7 +951,7 @@ def u_username_wall(v, username): is_following = v and u.has_follower(v) if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"): - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id) + gevent.spawn(_add_profile_view, v.id, u.id) page = get_page() @@ -998,10 +998,10 @@ def u_username_wall_comment(v, username, cid): is_following = v and u.has_follower(v) if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"): - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id) + gevent.spawn(_add_profile_view, v.id, u.id) if v and request.values.get("read"): - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _mark_comment_as_read, comment.id, v.id) + gevent.spawn(_mark_comment_as_read, comment.id, v.id) try: context = min(int(request.values.get("context", 8)), 8) except: context = 8 @@ -1043,7 +1043,7 @@ def u_username(v, username): return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403 if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"): - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id) + gevent.spawn(_add_profile_view, v.id, u.id) sort = request.values.get("sort", "new") t = request.values.get("t", "all") @@ -1110,7 +1110,7 @@ def u_username_comments(username, v): return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403 if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"): - gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id) + gevent.spawn(_add_profile_view, v.id, u.id) page = get_page()