From 728ee59f279505dbce1acaccfcb81524117d2372 Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Tue, 15 Aug 2017 11:55:39 -0700 Subject: [PATCH] PYTHON-1350 - Work around getsockopt issue on NetBSD NetBSD doesn't support testing TCP_KEEPIDLE and friends, only setting them. --- doc/changelog.rst | 15 +++++++++++++++ pymongo/pool.py | 12 +++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 4e4208688..201d77162 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,21 @@ Changelog ========= +Changes in Version 3.5.1 +------------------------ + +Version 3.5.1 fixes bugs reported since the release of 3.5.0: + +- Work around socket.getsockopt issue with NetBSD. + +Issues Resolved +............... + +See the `PyMongo 3.5.1 release notes in JIRA`_ for the list of resolved issues +in this release. + +.. _PyMongo 3.5.1 release notes in JIRA: https://jira.mongodb.org/projects/PYTHON/versions/18721 + Changes in Version 3.5 ---------------------- diff --git a/pymongo/pool.py b/pymongo/pool.py index 881118821..b3e5ef721 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -150,9 +150,15 @@ else: def _set_tcp_option(sock, tcp_option, max_value): if hasattr(socket, tcp_option): sockopt = getattr(socket, tcp_option) - default = sock.getsockopt(socket.SOL_TCP, sockopt) - if default > max_value: - sock.setsockopt(socket.SOL_TCP, sockopt, max_value) + try: + # PYTHON-1350 - NetBSD doesn't implement getsockopt for + # TCP_KEEPIDLE and friends. Don't attempt to set the + # values there. + default = sock.getsockopt(socket.IPPROTO_TCP, sockopt) + if default > max_value: + sock.setsockopt(socket.IPPROTO_TCP, sockopt, max_value) + except socket.error: + pass def _set_keepalive_times(sock): _set_tcp_option(sock, 'TCP_KEEPIDLE', _MAX_TCP_KEEPIDLE)