This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: socket.SO_KEEPALIVE does not work on FreeBSD
Type: behavior Stage:
Components: FreeBSD, IO, Library (Lib) Versions: Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, koobs, porton
Priority: normal Keywords:

Created on 2016-11-28 19:17 by porton, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py porton, 2016-11-28 19:17 A tiny server to check the bug
bug.php porton, 2016-11-28 19:43 Similar bug in PHP
Messages (3)
msg281911 - (view) Author: Victor Porton (porton) Date: 2016-11-28 19:17
When I connect

telnet XXX 9000

to the server in attached file, the connection breaks after 5 min (and a few seconds), as if SO_KEEPALIVE were not specified.

I run my server on
FreeBSD 9.2-RELEASE-p15 (GENERIC)

So SO_KEEPALIVE does not work in Python 2.7 and 3.5 on FreeBSD.

Specifically, I need my TCP connection not to break in extended periods of time and cannot do this with Python.

It seems that similar code does work with PHP (I am going to write a short PHP example), so it is likely a Python bug, not FreeBSD bug.
msg281913 - (view) Author: Victor Porton (porton) Date: 2016-11-28 19:43
Weird, after I minimized the PHP example, it also has the same bug as the Python one. (The real long code in PHP was working without this bug.)

I attach the PHP code for your reference.

Maybe it is a FreeBSD bug?

Please write to porton@narod.ru with advice how to make the server not to disconnect after 5 minutes of idle connection.
msg281957 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2016-11-29 07:42
Python just passes socket options to the operating system, so whatever behavior you're seeing is likely part of the OS.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73011
2016-11-29 07:42:36benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg281957

resolution: not a bug
2016-11-28 19:43:42portonsetfiles: + bug.php

messages: + msg281913
2016-11-28 19:17:08portoncreate