Fix: correctly close metadata on sessiond thread shutdown

Introduce a _close_metadata() function that does not take any locks so
it can be used by multiple call sites with different locking scheme.

Signed-off-by: David Goulet <dgoulet@efficios.com>