pike.git / lib / modules / Sql.pmod / pgsql.pike

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:889:    break;    default:errtype=protocolerror;    case 2:extrainfo=ts[1];    case 1:condition=ts[0];    }    }    PD("%d %s\n%s\n",pid,condition,extrainfo);    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)    errtype=protocolerror;    switch(errtype) {    case protocolunsupported:    ERROR("Unsupported servermessage received %c\n",msgtype);    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;    }    if(zero_type(waitforstate))    break;    }    PD("Found state %O\n",_mstate);    return _mstate;   }
pike.git/lib/modules/Sql.pmod/pgsql.pike:940:    cancelquery();    if(_c)    _c.sendterminate();   }      void destroy() {    close();   }      private void reconnect(void|int force) { +  Thread.MutexKey connectmtxkey;    if(_c) {    reconnected++;    prepstmtused=0;   #ifdef DEBUG    ERROR("While debugging, reconnects are forbidden\n");    exit(1);   #endif    if(!force)    _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);    _closesent=0;    _mstate=unauthenticated;    qstate=queryidle;    runtimeparameter=([]);    array(string) plugbuf=({"",_c.plugint32(PG_PROTOCOL(3,0))});    if(user)    plugbuf+=({"user\0",user,"\0"});