fix(downloads): a download that hangs up mid-transfer is not an error at the egress gate
Seen live: yt-dlp closes a connection once it has read what it needed, and the gate printed a traceback for each. A reset ends the tunnel quietly; anything else the gate cannot finish is a log line with its code, not bare stderr.
This commit is contained in:
@@ -10,7 +10,9 @@ import http.server
|
||||
import ipaddress
|
||||
import socket
|
||||
import socketserver
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -178,6 +180,24 @@ def test_a_tunnel_into_the_network_is_refused_before_it_is_dialled(gate):
|
||||
internal.close()
|
||||
|
||||
|
||||
def test_a_client_that_hangs_up_mid_transfer_is_not_an_error(gate, monkeypatch):
|
||||
# yt-dlp closes a connection once it has read what it needed; seen live as a traceback the gate
|
||||
# printed for every such download.
|
||||
errors_seen = []
|
||||
monkeypatch.setattr(gate, "handle_error", lambda *a: errors_seen.append(a))
|
||||
public = _public_server({"/big": (200, {}, b"x" * 4_000_000)})
|
||||
try:
|
||||
s = socket.create_connection(("127.0.0.1", gate.server_address[1]))
|
||||
s.sendall(f"GET http://{PUBLIC}:{public.server_address[1]}/big HTTP/1.1\r\n\r\n".encode())
|
||||
s.recv(1024)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0))
|
||||
s.close() # a reset, not a polite close
|
||||
time.sleep(0.5)
|
||||
assert errors_seen == []
|
||||
finally:
|
||||
public.shutdown()
|
||||
|
||||
|
||||
# --- a real yt-dlp through it ----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user