Add sychronization around access to middleware.
This is necessary, because even though it is on the affinity thread, start/stop of the
server may result in different threads accessing it.

Change-Id: I22121233e26640052fa50d480b1c9c9a35e749c9