Package: python3-pymssql
Version: 2.1.4+dfsg-3+b3
When re-connecting to an MSSQL server after a connection error, the
program will stop with "malloc(): unsorted double linked list corrupted"
This can be reproduced on Debian 11.6 (amd64) with latest dist-upgrade
applied using the following program. The test program will run in a
loop, doing heavy work, and reconnect if the connection should fail.
A malicious administrator might kill the database connection:
DECLARE @spid INT
SELECT @spid=spid FROM sys.sysprocesses
WHERE program_name LIKE 'Trigger Error %'
EXEC ('KILL ' + @spid)
The application should create a new connection and go on, but in most
cases the malloc() abort will happen.
#! /usr/bin/python3
##########################################################
import os, json, pymssql
"""
Configuration in ~/db.secrets
{
"server": "serverAddress",
"database": "theDatabase",
"username": "theUser",
"password": "secrets"
}
"""
with open(f"{os.path.expanduser('~')}/db.secrets") as fp:
cfg=json.load(fp)
def getCursor(appname):
print("Making new connection", appname)
conn=pymssql.connect(cfg['server'], cfg['username'],
cfg['password'], cfg['database'],
port=cfg.get('port', 1433), as_dict=True,
timeout=20, login_timeout=5,
appname=appname)
return conn.cursor()
generation=1
cursor=None
while True:
if not cursor:
cursor=getCursor(f"Trigger Error {generation}")
try:
print("Executing generation", generation)
cursor.execute("WAITFOR DELAY '00:00:01'")
except (pymssql.OperationalError, pymssql.InterfaceError) as e:
print("Aborted", e)
cursor=None
generation += 1