diff --git a/pymisp/api.py b/pymisp/api.py index ae96745..784c43e 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -28,6 +28,17 @@ from .mispevent import MISPEvent, MISPAttribute, MISPSighting, MISPLog, MISPObje MISPGalaxyCluster, MISPGalaxyClusterRelation, MISPCorrelationExclusion from .abstract import pymisp_json_default, MISPTag, AbstractMISP, describe_types + +# Enable TCP keepalive by default on every requests +import socket +from urllib3.connection import HTTPConnection +HTTPConnection.default_socket_options = HTTPConnection.default_socket_options + [ + (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), # enable keepalive + (socket.SOL_TCP, socket.TCP_KEEPIDLE, 30), # Start pinging after 30s of idle time + (socket.SOL_TCP, socket.TCP_KEEPINTVL, 10), # ping every 10s + (socket.SOL_TCP, socket.TCP_KEEPCNT, 6) # kill the connection if 6 ping fail (60s total) +] + try: # cached_property exists since Python 3.8 from functools import cached_property # type: ignore