Skip to content

fix(transport): Add extra socket options to the connection pool to fi… #1323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sentry_sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import io
import urllib3 # type: ignore
from urllib3.connection import HTTPConnection
import certifi
import gzip
import time
import socket

from datetime import datetime, timedelta
from collections import defaultdict
Expand Down Expand Up @@ -397,10 +399,21 @@ def _send_envelope(

def _get_pool_options(self, ca_certs):
# type: (Optional[Any]) -> Dict[str, Any]
extra_socket_options = []
if hasattr(socket, "SO_KEEPALIVE"):
extra_socket_options.append((socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1))
if hasattr(socket, "TCP_KEEPIDLE"):
extra_socket_options.append((socket.SOL_TCP, socket.TCP_KEEPIDLE, 45))
if hasattr(socket, "TCP_KEEPINTVL"):
extra_socket_options.append((socket.SOL_TCP, socket.TCP_KEEPINTVL, 10))
if hasattr(socket, "TCP_KEEPCNT"):
extra_socket_options.append((socket.SOL_TCP, socket.TCP_KEEPCNT, 6))
return {
"num_pools": 2,
"cert_reqs": "CERT_REQUIRED",
"ca_certs": ca_certs or certifi.where(),
"socket_options": HTTPConnection.default_socket_options
+ extra_socket_options,
}

def _in_no_proxy(self, parsed_dsn):
Expand Down