Uploaded image for project: 'Geode'
  1. Geode
  2. GEODE-6927

possible NPE in ConnectionTable.getThreadOwnedConnection if concurrent close

    XMLWordPrintableJSON

Details

    Description

      ConnectionTable.getThreadOwnedConnection has a couple of usages of "this.threadConnectionMap" that could result in an NPE if the ConnectionTable is concurrently closed.
      The unsafe code:

          if (this.threadConnectionMap == null) {
            // This instance is being destroyed; fail the operation
            closeCon(
                "Connection table being destroyed",
                result);
            return null;
          }
      
          ArrayList al = (ArrayList) this.threadConnectionMap.get(id);
          if (al == null) {
            // First connection for this DistributedMember. Make sure list for this
            // stub is created if it isn't already there.
            al = new ArrayList();
      
            // Since it's a concurrent map, we just try to put it and then
            // return whichever we got.
            Object o = this.threadConnectionMap.putIfAbsent(id, al);
            if (o != null) {
              al = (ArrayList) o;
            }
          }
      

      If a close happens after the initial null check but before either the get or putIfAbsent call then a NPE will be thrown.
      All the other code that uses "threadConnectionMap" is careful to save it into a local var, and then use the local var. That is all that is needed here to make this code thread safe.

      Attachments

        Issue Links

          Activity

            People

              echobravo Ernest Burghardt
              dschneider Darrel Schneider
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h