[VOL-4432] wait for all messages to be sent before closing the channel

Change-Id: If8ff1f08b445ab627edc34e88b24764fdc49251c
diff --git a/VERSION b/VERSION
index 227cea2..1e4ec5e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.0.0
+2.0.1-dev
diff --git a/internal/pkg/openflow/connection.go b/internal/pkg/openflow/connection.go
index 6dce658..1806a99 100644
--- a/internal/pkg/openflow/connection.go
+++ b/internal/pkg/openflow/connection.go
@@ -188,6 +188,14 @@
 			case ofcEventStop:
 				logger.Debugw(ctx, "ofc-event-stop",
 					log.Fields{"device-id": ofc.DeviceID})
+				// check for empty send channel to make sure we are not loosing any message to the controller
+				for len(ofc.sendChannel) != 0 {
+					logger.Debugw(ctx, "wait-for-empty-send-channel-to-close-connection",
+						log.Fields{
+							"device-id":      ofc.DeviceID,
+							"len of channel": len(ofc.sendChannel),
+							"event":          event.String()})
+				}
 				if state == ofcStateCreated || state == ofcStateConnected || state == ofcStateDisconnected {
 					state = ofcStateStopped
 					break top