Bug #69088 Connection fails on older versions of FreeBSD
Submitted: 27 Apr 2013 16:33 Modified: 15 Nov 2013 13:04
Reporter: George Polishchuk Email Updates:
Status: Closed Impact on me:
Category:Connector / Python Severity:S3 (Non-critical)
Version:1.0.9 OS:FreeBSD (6.2)
Assigned to: CPU Architecture:Any
Tags: freebsd, Mysql Connector Python

[27 Apr 2013 16:33] George Polishchuk
MySQL connection fails on older versions of FreeBSD. Seems to be a FreeBSD bug. socket.getaddrinfo error 

server# uname -a
FreeBSD media 6.2-RELEASE FreeBSD 6.2-RELEASE #1: Sun Dec 16 16:06:40 EET 2007     admin@test.test:/usr/src/sys/i386/compile/SYS001  i386

server# python3 --version
Python 3.3.0

2003: Can't connect to MySQL server on 'localhost' ([Errno 9] servname not supported for ai_socktype) Traceback (most recent call last):

How to repeat:
Just run python 3 program with MySQL connector on older version of FreeBSD

Suggested fix:
--- \mysql-connector-python-1.0.9\python3\mysql\connector\network.py 
+++ \mysql-connector-python-1.0.9\python3\mysql\connector\network.py 
@@ -337,7 +337,7 @@
         addrinfo = None
             addrinfos = socket.getaddrinfo(self.server_host, self.server_port,
-                                           0, 0, socket.SOL_TCP)
+                                           0, socket.SOCK_STREAM, socket.SOL_TCP)
             # If multiple results we favor IPv4, unless IPv6 was forced.
             for info in addrinfos:
                 if self.force_ipv6 and info[0] == socket.AF_INET6:
[6 Aug 2013 13:12] Andrii Nikitin
Thank you for the report.

According to official python 3.3 documentation at http://docs.python.org/3.3/library/socket.html#socket.getaddrinfo

In these tuples, family, type, proto are all integers and are meant to be passed to the socket() function. 

But later later, at http://docs.python.org/3.3/library/socket.html#socket.socket

it doesn't appear that type=0 is valid constant, because relevant constants in sys/socket.h start with 1.

It looks that type=0 is handled properly on most of systems, but still it isn't valid value for "type" parameter. 

Thus putting this to "Verified".
[15 Nov 2013 13:04] Paul DuBois
Noted in 1.1.3 changelog.

Connection attempts failed on older versions of FreeBSD.