Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segfault on 2nd connection with pyodbc to mirrored MS SQL Server

I'm facing an issue with a Python script that connects to a mirrored MS SQL server DB. It's throwing a segmentation fault when I try connecting to the DB for the second time. Both the app server and the DB instances are running on Google Compute Engine.

Here's some code replicating the issue:

import pyodbc

params = {
   'autocommit': True,
   'uid': 'myuser',
   'tds_version': '8.0',
   'DRIVER': '{mssql}',
   'pwd': 'mypassword',
   'server': 'sql-server-01',
   'database': 'mydb',
   'port': 1433,
}

c1 = pyodbc.connect(**params)
c2 = pyodbc.connect(**params)

The first connection (c1) succeeds, but the second connection (c2) fails immediately with segfault. "mydb" is mirrored to a second server (sql-server-02). Using a non-mirrored DB, or disabling mirroring for this DB, makes it go away.

We have tried upgrading several libs, and that didn't fix the issue. Versions:

  • Microsoft SQL Server: 12.00.2000 (latest)
  • Python: 2.7.6
  • pyodbc: 3.0.10 (latest)
  • unixODBC: 2.2.14p2-5ubuntu5, 2.3.0, 2.3.4 (latest)
  • MS ODBC driver for RedHat: 11.0.1790.0, 11.0.2270.0 (latest)

To add here, Java code performing the same steps works fine.

Any ideas?

like image 796
Max Twardowski Avatar asked Oct 09 '15 21:10

Max Twardowski


1 Answers

The MSODBC driver has a lot of known issues, especially with multithreading. It sounds like you're running into this. I ran into it with Django's runserver; it would only work (and still with bugs in SQLRowCount) with the --nothreading option for Django's runserver.

Fortunately, Microsoft is now assembling a team to make a better performing, reliable driver (thank you, MS!). In the meantime, I use FreeTDS 0.95 (which supports up to TDS version 7.3, a la SQL Server 2008), which has treated me very well. Give that a try? Good luck.

like image 116
FlipperPA Avatar answered Nov 15 '22 11:11

FlipperPA