Branch: Tag:

2020-05-18

2020-05-18 17:16:31 by Stephen R. van den Berg <srb@cuci.nl>

pgsql: Release a portal only once (destructor becomes a no-op).

593:    mode = SENDOUT;    break;    case FLUSHLOGSEND: -  PD("%d>%O %d Queue simplequery %d bytes\n", socket->query_fd(), -  portal._portalname, ++queueoutidx, sizeof(this)); +  PD("%d>%d Queue simplequery %d bytes\n", +  socket->query_fd(), ++queueoutidx, sizeof(this));    mode = FLUSHSEND;    }    qportals->write(synctransact++);
952:    reflock[0] = lock;    lock = 0;    if (!_sendexecute(0, reflock)) { +  PD("Status_command_complete retry closemux %O\n", _portalname);    lock = closemux->lock();    continue;    }
1268:    if (sizeof(dtoid) != sizeof(paramValues))    SUSERERROR("Invalid number of bindings, expected %d, got %d\n",    sizeof(dtoid), sizeof(paramValues)); +  PD("PrepareBind\n");    Thread.MutexKey lock = _ddescribemux->lock();    if (!_portalname) {    _portalname
1539:    if (!datarowtypes) {    if (_tprepared && dontcacheprefix->match(_query))    m_delete(pgsqlsess->prepareds, _query), _tprepared = 0; +  PD("WaitForDescribe\n");    waitfordescribe();    } -  +  PD("About to bind %d\n", _state);    if (_state >= CLOSING)    lock = _unnamedstatementkey = 0;    else {
1587:    if ((syncparse || syncparse < 0 && pgsqlsess->wasparallelisable)    && !pgsqlsess->statementsinflight->drained()) {    lock = 0; // Unlock while we wait -  PD("Commit waiting for statements to finish\n"); +  PD("Commit waiting for statements to finish %d\n", +  pgsqlsess->statementsinflight->_count);    catch(PT(pgsqlsess->statementsinflight->wait_till_drained())); -  +  PD("Parseportal retry closemux %O\n", _portalname);    continue;    }    _state = PARSING;
1684:    if (inflight <= (_fetchlimit - 1) >> 1) {    array(Thread.MutexKey) reflock = ({ lock });    lock = 0; -  if (!_sendexecute(_fetchlimit, reflock)) +  if (!_sendexecute(_fetchlimit, reflock)) { +  PD("Replenishrows retry closemux %O\n", _portalname);    continue; -  +  }    } else    PD("<%O _fetchlimit %d, inflight %d, skip execute\n",    _portalname, _fetchlimit, inflight);
1721:    }       final void _releasesession(void|string statusccomplete) { +  int aborted = statusccomplete == "ABORT" ? 2 : 0;    c->runningportals[this] = 0;    if (statusccomplete && !statuscmdcomplete) {    Thread.MutexKey lock = _ddescribemux->lock();
1731:    conxsess plugbuffer;    array(Thread.MutexKey) reflock = ({ 0 });    for (;;) { -  reflock[0] = closemux->lock(); -  if (!catch(plugbuffer = c->start(reflock))) { +  reflock[0] = closemux->lock(aborted); +  if (!catch(plugbuffer = c->start(reflock)))    if (plugbuffer)    plugbuffer->sendcmd(_closeportal(plugbuffer, reflock)); -  else +  else { +  PD("Releasesession retry closemux %O\n", _portalname);    continue;    }    break;
1746:    _state = CLOSED;    }    datarows->write(1); // Signal EOF -  releaseconditions(statusccomplete == "ABORT"); +  releaseconditions(aborted);    }       protected void _destruct() { -  catch { // inside destructors, exceptions don't work +  if (_state < CLOSED) +  catch { // inside destructors, exceptions don't work    _releasesession("ABORT");    };    }
2059: Inside #if defined(PG_DEBUG)
   ->add_int32(backendpid)->add(cancelsecret)->sendcmd(FLUSHSEND));   #ifdef PG_DEBUG    if (err) -  PD("CancelRequest failed to connect %O\n", describe_backtrace(err)); +  PD("CancelRequest failed to connect %s\n", describe_backtrace(err));   #endif    destruct(lcon); // Destruct explicitly to avoid delayed close   #ifdef PG_DEBUGMORE
2692:    switch (msgresponse.S) {    case "PANIC":werror(a2nls(lastmessage));    } -  case "25P02": // Preserve last error message +  case "25P02": // Preserve last error message    USERERROR(a2nls(lastmessage)); // Implicitly closed portal    }    break;
2700:    case 'N': {    PD("NoticeResponse\n");    mapping(string:string) msgresponse = getresponse(); +  switch (msgresponse.C) { +  default:    if (clearmessage) {    warningsdropcount += warningscollected;    clearmessage = warningscollected = 0;
2713:    preplastmessage(msgresponse);    PD(a2nls(lastmessage)); throw(val);    } +  case "25P01": // Suppress some warnings    break;    } -  +  break; +  }    case 'A': {    PD("NotificationResponse\n");    msglen -= 4 + 4;