<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 16: spurious db reconnections in shared db environment</title><link>https://sourceforge.net/p/sqlgrey/bugs/16/</link><description>Recent changes to 16: spurious db reconnections in shared db environment</description><atom:link href="https://sourceforge.net/p/sqlgrey/bugs/16/feed.rss" rel="self"/><language>en</language><lastBuildDate>Mon, 05 May 2008 01:46:44 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/sqlgrey/bugs/16/feed.rss" rel="self" type="application/rss+xml"/><item><title>spurious db reconnections in shared db environment</title><link>https://sourceforge.net/p/sqlgrey/bugs/16/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;We have 3 front end postfix servers fed SMTP by a load balancer, each running &lt;br /&gt;
sqlgrey-1.6.7 with a single mysql backend shared by all 3.&lt;/p&gt;
&lt;p&gt;We see several spurious reconnections of the db each day; however &lt;br /&gt;
the logs didn't show clearly what was going on until I fixed some code&lt;br /&gt;
that was erroneously trying to display $DBI::errstr after the database &lt;br /&gt;
had been closed; see patch below.&lt;/p&gt;
&lt;p&gt;$DBI::errstr is undefined when the database is closed.&lt;/p&gt;
&lt;p&gt;May  2 15:17:01 MYHOST sqlgrey: warning: Use of uninitialized value in concatenation (.) or string at /opt/local/sbin/sqlgrey line 227.&lt;br /&gt;
May  2 15:17:01 MYHOST sqlgrey: dbaccess: warning: couldn't do query:\nINSERT INTO from_awl (sender_name, sender_domain, src, first_seen, last_seen) VALUES('acf','blah.com','1.2.3','2008-05-02 15:06:25',NOW()):\n, reconnecting to DB&lt;/p&gt;
&lt;p&gt;*** sqlgrey.orig        Sat May 20 03:22:07 2006&lt;br /&gt;
--- sqlgrey     Sat May  3 12:51:17 2008&lt;br /&gt;
***************&lt;br /&gt;
*** 223,232 ****&lt;br /&gt;
return $result;&lt;br /&gt;
} else {&lt;br /&gt;
# failure&lt;br /&gt;
$self-&amp;gt;db_unavailable();&lt;br /&gt;
$self-&amp;gt;mylog('dbaccess', 0, "warning: couldn't do query:\n" .&lt;br /&gt;
"$query:\n" .&lt;br /&gt;
!                  "$DBI::errstr, reconnecting to DB");&lt;br /&gt;
return undef;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
--- 223,233 ----&lt;br /&gt;
return $result;&lt;br /&gt;
} else {&lt;br /&gt;
# failure&lt;br /&gt;
+       my($e) = "$DBI::errstr";&lt;br /&gt;
$self-&amp;gt;db_unavailable();&lt;br /&gt;
$self-&amp;gt;mylog('dbaccess', 0, "warning: couldn't do query:\n" .&lt;br /&gt;
"$query:\n" .&lt;br /&gt;
!                  "$e, reconnecting to DB");&lt;br /&gt;
return undef;&lt;br /&gt;
}&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;From code inspection the latest version 1.7.6 also has&lt;br /&gt;
this problem, and in a number of places.&lt;/p&gt;
&lt;p&gt;Once the above patch was applied, it became obvious what was&lt;br /&gt;
actually causing the spruious reconnections... duplicate key's&lt;br /&gt;
when inserting from_awl entries.&lt;/p&gt;
&lt;p&gt;May  4 11:59:39 MYHOST sqlgrey: dbaccess: warning: couldn't do query:\nINSERT INTO from_awl (sender_name, sender_domain, src, first_seen, last_seen) VALUES('blah','blah.com','1.2.3','2008-05-04 11:32:08',NOW()):\nDuplicate entry '1.2.3-blah.com-blah' for key 1, reconnecting to DB&lt;/p&gt;
&lt;p&gt;The code has a race condition between checking if a given from_awl&lt;br /&gt;
entry has been inserted and inserting one because it thought it wasn't&lt;br /&gt;
there... that shows up when multiple sqlgrey's are sharing the same&lt;br /&gt;
database.&lt;/p&gt;
&lt;p&gt;A simple fix would be to check for the duplicate-key error on all&lt;br /&gt;
inserts of this nature, and silently forge on if found, rather than &lt;br /&gt;
considering this a database error and noisily doing a reconnecticon.&lt;/p&gt;
&lt;p&gt;Otherwise I've been using this version for a couple of years now&lt;br /&gt;
and its worked flawlessly.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ian Donaldson</dc:creator><pubDate>Mon, 05 May 2008 01:46:44 -0000</pubDate><guid>https://sourceforge.net14e6a59821035dc091e5899f33d0fc4a4637b90e</guid></item></channel></rss>