greenlaw110/play-morphia — pull request #118 by kapilpendse (2014-01-17 09:31:31+00:00)
Title: Close MongoDB connection in onApplicationStop() to release resources.

In our Play 1.2.5 based application, we observed that in DEV mode, some code changes would trigger Play's detectChanges() to restart the application. This is done by Play by calling stop() followed by start(). For modules, this results in calls to onApplicationStop() followed by onApplicationStart().

If onApplicationStop() doesn't close Mongo connection, the following onApplicationStart() causes an InterruptedException deep inside Java MongoDB driver, in a Semaphore#tryAcquire() call. Eventually, the entire application becomes unstable and crashes.