Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28660

memory leak of mongodb database with SSL support

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 3.4.2
    • Component/s: Security
    • None
    • Environment:
      The client is a Java program. Server: operating system: Ubuntu 16, CPU: 4 core 3.4GHZ, RAM:8GB, database: Mongodb 3.4 Community version

      We have Mongodb database server runs with SSL support, the config file about SSL is below, The certificate is self sign created with OpenSSL,
      /etc/mongod.conf

      net:
        port: 27017
      #  bindIp: 127.0.0.1
        ssl:
          mode: requireSSL
          PEMKeyFile: /home/puma/atlas-ssl.pem
      

      The clients is a Java multi thread program, write a record into Mongodb database every minute,

      import java.util.Date;
      import java.util.concurrent.ExecutorService;
      import java.util.concurrent.Executors;
      
      import org.bson.Document;
      
      import com.mongodb.MongoClient;
      import com.mongodb.MongoClientURI;
      import com.mongodb.client.MongoCollection;
      import com.mongodb.client.MongoDatabase;
      
      public class PressureTest {
      	public static void main(String[] args) {
      		ExecutorService executor = Executors.newFixedThreadPool(100);
      		for (int i = 0; i < 100; i++) {
      			Runnable worker = new WorkerThread();
      			executor.execute(worker);
      		}
      	}
      }
      
      class WorkerThread implements Runnable {
      
      	@Override
      	public void run() {
      		System.setProperty("javax.net.ssl.trustStore",
      				"C:/ssl/atlas-truststore.ts");
      		System.setProperty("javax.net.ssl.trustStorePassword", "password");
      		while (true) {
      			insert();
      			hangup();
      		}
      	}
      
      	private void hangup() {
      		try {
      			Thread.sleep(60000);
      		} catch (InterruptedException e) {
      			e.printStackTrace();
      		}
      	}
      
      	private void insert() {
      		MongoClient client = null;
      		try {
      			if (client == null) {
      				client = new MongoClient(new MongoClientURI(
      						"mongodb://192.168.244.193:27017/atlas?ssl=true&sslInvalidHostNameAllowed=true"));
      			}
      			MongoDatabase db = client.getDatabase("atlas");
      			MongoCollection<Document> collection = db.getCollection("operating_data");
      				document.put("serialNumber", Thread.currentThread().getName());
      			document.put("timestamp", new Date());
      			document.put("FWver", "01.00.00");
      			document.put("HWver", "03");
      			document.put("harmonizerModel", "String");
      			document.put("bypassTap1", "00.0");
      			document.put("lowTap", "00.00");
      			document.put("medTap", "00.00");
      			document.put("highTap", "00.00");
      			document.put("id", 0);
      			document.put("msg", "Message string");
      			collection.insertOne(document);
      		} catch (Exception e) {
      		} finally {
      			if (client != null) {
      				client.close();
      			}
      		}
      	}
      }
      

      The issue is that the memory usage of Mongodb server keeps going up until the server throw out of memory error and mongodb service is collapsed.
      Do you guys have any suggestion for this issue? I appreciate your help so much!

      John

        1. diagnostic_data.docx
          30 kB
          John Wang [X]

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            John_Wang John Wang [X]
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: