Fix deadlock introduced in bd613df2
Fix deadlock introduced in bd613df2

Commit bd613df2 prevented data corruption due to simultaneous
driver.CreateNetwork()/driver.DeleteNetwork() by holding the network
lock through the read/modify part of the operation.  However, part of
the DeleteNetwork operation entails sending a message to the peerDB to
tell that goroutine to flush entries on deletion.  This can lead to a
deadlock where:
  * driver.DeleteNetwork() starts and acquires driver.Lock()
  * peerDB receives some other request (e.g. EventNotify) and blocks
    on driver.Lock()
  * driver.DeleteNetwork() attempts a peerDB flush and blocks waiting
    on the synchronous peerDB operation channel

This patch fixes the issue by deferring the peerDB flush operation until
after DeleteNetwork() unlocks driver.Lock().   Commit bd613df2 only
modified CreateNetwork() and DeleteNetwork() and the critical section
that driver.Lock() protects in CreateNetwork() does not perform any
peerDB notifications or other locks of driver data structures.  So this
solution should be a complete fix for any regressions introduced in
bd613df2.

Signed-off-by: Chris Telfer <9cf1a5ba8f085fe3bf87fd3e4704febafc338899@docker.com>

medallia/libnetwork,abhi/libnetwork,mahak/libnetwork,medallia/libnetwork,medallia/libnetwork,docker/libnetwork,mahak/libnetwork,vdemeester/libnetwork,docker/libnetwork,vdemeester/libnetwork,vdemeester/libnetwork,abhi/libnetwork,docker/libnetwork,abhi/libnetwork,mahak/libnetwork