tests: make the telnet server shut down a socket gracefully

- test 1452 failed occasionally with ECONNRESET errnos in curl when the
  server closed the connection in an unclean state.

Closes #10509
This commit is contained in:
Stefan Eissing 2023-02-14 14:29:13 +01:00 коммит произвёл Daniel Stenberg
Родитель 87ed650d04
Коммит 79d0b3c0c0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5CC908FDB71E12C2
1 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -29,7 +29,9 @@ from __future__ import (absolute_import, division, print_function,
import argparse
import logging
import os
import socket
import sys
import time
from util import ClosingFileHandler
@ -90,7 +92,7 @@ class NegotiatingTelnetHandler(socketserver.BaseRequestHandler):
neg.send_wont("NAWS")
# Get the data passed through the negotiator
data = neg.recv(1024)
data = neg.recv(4*1024)
log.debug("Incoming data: %r", data)
if VERIFIED_REQ.encode('utf-8') in data:
@ -109,6 +111,12 @@ class NegotiatingTelnetHandler(socketserver.BaseRequestHandler):
log.debug("Sending %r", response_data)
self.request.sendall(response_data)
# put some effort into making a clean socket shutdown
# that does not give the client ECONNRESET
self.request.settimeout(0.1)
self.request.recv(4*1024)
self.request.shutdown(socket.SHUT_RDWR)
except IOError:
log.exception("IOError hit during request")