Branch: Tag:

2017-11-09

2017-11-09 11:15:11 by Stephen R. van den Berg <srb@cuci.nl>

pgsql: Cater for race during asynchronous destruction of bufcon.

172:      class bufcon {    inherit Stdio.Buffer; +  private int dirty;      #ifdef PG_DEBUGRACE    final bufcon `chain() {
190:    }       final bufcon start(void|int waitforreal) { +  dirty = 1;    realbuffer->stashcount++; -  +  dirty = 2;   #ifdef PG_DEBUG    if(waitforreal)    error("pgsql.bufcon not allowed here\n");
212:    realbuffer->socket->query_fd(), mode, realbuffer->stashflushmode);    if (mode > realbuffer->stashflushmode)    realbuffer->stashflushmode = mode; +  dirty = 1;    if(!--realbuffer->stashcount) -  realbuffer->stashavail.signal(); +  dirty = 0, realbuffer->stashavail.signal(); +  else +  dirty = 0;    lock=0;    this->clear();    if(lock=realbuffer->nostash->trylock(1)) {
229:   #endif    }    } +  +  protected void _destruct() { +  switch (dirty) { +  case 1: +  werror("FIXME: Race condition detected %s\n", +  describe_backtrace(({"", backtrace()[..<1]}))); +  if (!realbuffer->stashcount) +  break; +  case 2: +  Thread.MutexKey lock = realbuffer->shortmux->lock(2); +  if (!--realbuffer->stashcount) +  realbuffer->stashavail.signal(); +  lock = 0; +  } +  }   };      class conxiin {
340:    return this;   #endif    } -  stashcount++; -  return bufcon(this); +  return bufcon(this)->start();    }       private int write_cb() {
518:    catch(fd=socket->query_fd());    res=predef::sprintf("conxion fd: %d input queue: %d/%d "    "queued portals: %d output queue: %d/%d\n" -  "started: %d\n", +  "started: %d stashcount: %d\n",    fd,sizeof(i),i->_size_object(),    qportals && qportals->size(), sizeof(this), _size_object(), -  !!started); +  !!started, stashcount);    break;    }    return res;