Branch: Tag:

2008-08-21

2008-08-21 10:13:42 by Stephen R. van den Berg <srb@cuci.nl>

pgsql detect and act on surprise connection loss

Rev: lib/modules/Sql.pmod/pgsql.pike:1.30

896:    runcallback(pid,condition,extrainfo);    break;    } -  default:PD("Unknown message received %c\n",msgtype); +  default: +  if(msgtype!=-1) { +  PD("Unknown message received %c\n",msgtype);    msglen-=4;PD("%O\n",_c.getstring(msglen));msglen=0;    errtype=protocolunsupported; -  +  } +  else { +  string msg=lastmessage?lastmessage+"\n":""; +  reconnect(1); +  ERROR("%sConnection lost to database %s@%s:%d/%s %d\n", +  msg,user,host,port,database,backendpid); +  }    break;    }    if(msglen)
909:    break;    case protocolerror:    reconnect(1); -  ERROR("Protocol error with databasel %s@%s:%d/%s\n", -  user,host,port,database); +  ERROR("Protocol error with database %s@%s:%d/%s PID %d\n", +  user,host,port,database,backendpid);    break;    case noerror:    break;
947:   }      private void reconnect(void|int force) { +  Thread.MutexKey connectmtxkey;    if(_c) {    reconnected++;    prepstmtused=0;
958:    _c.sendterminate();    foreach(prepareds;;mapping tp)    m_delete(tp,"preparedname"); +  if(!(connectmtxkey = _stealmutex.trylock(2))) +  ERROR("Recursive reconnect, bailing out\n");    }    if(!(_c=getsocket()))    ERROR("Couldn't connect to database on %s:%d\n",host,port);