Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1196

MongoDbConnection does not close MongoClient

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 2.2, 2.3, 2.4, 2.4.1
    • 2.5
    • Appenders
    • None

    Description

      When shutting down Log4J, e. g. during undeployment of a web application, the MongoClient opened by the MongoDbProvider must be closed by the MongoDbConnection.close() method. Otherwise the thread pool opened by the MongoClient will not get shutdown, since the MongoClient itself won't get closed.

      The quick fix is to remove the comments

              // there's no need to call this.mongo.close() since that literally closes the connection
              // MongoDBClient uses internal connection pooling
              // for more details, see LOG4J2-591
      

      from the "close()" method of MongoDbConnection, as it's very misleading and, actually, wrong.

      Instead, you really have to call

      this.mongo.close()

      here, because the "close()" method of the MongoDbConnection is called only when shutting down NoSqlDatabaseManager using shutdownInternal().

      My suggestion is to implement a similar strategy as used in the CouchDbConnection - using an AtomicBoolean flag to check whether "close()" has already been called.
      This way the code also works for the new MongoDB Java driver 3.x API.

      Attachments

        Activity

          People

            mattsicker Matt Sicker
            rzanner René Zanner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: