MB-9659: Destroy engine before releasing thread resources

Change-Id: If323b4a3a5ec29315d64a56fa043f405a57822e9
Reviewed-on: http://review.couchbase.org/30982
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>