MB-9659: Destroy engine before releasing thread resources

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