Branch: Tag:

2016-12-06

2016-12-06 13:28:32 by Stephen R. van den Berg <srb@cuci.nl>

pgsql: Reconnect logic was broken, works reliably now.

1178:    }    PD("Closing database processloop %O\n",err);    _delayederror=err; -  for(; objectp(portal); portal = qportals->read()) -  if(objectp(portal)) { +  if (objectp(portal)) {   #ifdef PG_DEBUG    showportal(0);   #endif
1227:      final void _connectfail(void|mixed err) {    PD("Connect failed %O reconnectdelay %d\n",err,reconnectdelay); -  destruct(waitforauthready); +     if(!err || reconnectdelay) {    int tdelay;    switch(tdelay=reconnectdelay) {
1237:    default:    if(err)    _delayederror=err; -  if(_options.reconnect!=-1) +  if (_options.reconnect!=-1) { +  destruct(waitforauthready); +  destruct(c);    return; -  +  }    reconnectdelay=RECONNECTBACKOFF;    break;    }
1258:    PD("(Re)connect\n");    {    Thread.MutexKey lock=_shortmux->lock(); -  if(waitforauthready) { -  lock=0; -  return 1; // Connect still in progress in other thread -  } +  if (!waitforauthready)    waitforauthready=Thread.Condition();    lock=0;    }
1272:    prepstmtused=0;   #endif    termlock=unnamedstatement->lock(1); -  c->close(); -  Thread.MutexKey lock = unnamedstatement->lock(1); +  catch(c->close()); +  unnamedstatement = 0; +  termlock = 0;    destruct(c); -  lock = 0; +     PD("Flushing old cache\n");    foreach(_prepareds;;mapping tp)    m_delete(tp,"preparedname");