Change vsync to use more idiomatic err != nil style.

The change to the "if err != nil" style doesn't change any
functionality.

I also noticed that syncService.cancelAdvSyncbase is set, but
never called.  Added a call in Close.

Change-Id: I89190355735510a4d6298d8d2d26d4532fa8a85a
diff --git a/services/syncbase/vsync/sync.go b/services/syncbase/vsync/sync.go
index d9ff29f..8fc5213 100644
--- a/services/syncbase/vsync/sync.go
+++ b/services/syncbase/vsync/sync.go
@@ -236,6 +236,7 @@
 	defer vlog.VI(2).Infof("sync: Close: end")
 
 	s := ss.(*syncService)
+	s.stopAdvertisingSyncbaseInNeighborhood()
 	close(s.closed)
 	s.pending.Wait()
 	s.bst.Close()
@@ -478,21 +479,28 @@
 		},
 	}
 
-	ctx, stop := context.WithCancel(s.ctx)
-
 	// Note that duplicate calls to advertise will return an error.
+	ctx, stop := context.WithCancel(s.ctx)
 	ch, err := idiscovery.AdvertiseServer(ctx, s.discovery, s.svr, "", &sbService, nil)
-
-	if err == nil {
-		vlog.VI(4).Infof("sync: advertiseSyncbaseInNeighborhood: successful")
-		s.cancelAdvSyncbase = func() {
-			stop()
-			<-ch
-		}
-		return nil
+	if err != nil {
+		stop()
+		return err
 	}
-	stop()
-	return err
+	vlog.VI(4).Infof("sync: advertiseSyncbaseInNeighborhood: successful")
+	s.cancelAdvSyncbase = func() {
+		stop()
+		<-ch
+	}
+	return nil
+}
+
+func (s *syncService) stopAdvertisingSyncbaseInNeighborhood() {
+	s.advLock.Lock()
+	cancelAdvSyncbase := s.cancelAdvSyncbase
+	s.advLock.Unlock()
+	if cancelAdvSyncbase != nil {
+		cancelAdvSyncbase()
+	}
 }
 
 // advertiseSyncgroupInNeighborhood checks if this Syncbase is an admin of the
@@ -550,7 +558,6 @@
 	if advertising {
 		sbService.Id = state.adId
 	}
-	ctx, stop := context.WithCancel(s.ctx)
 
 	vlog.VI(4).Infof("sync: advertiseSyncgroupInNeighborhood: advertising %v", sbService)
 
@@ -559,18 +566,19 @@
 	// if you match the In list you can see the advertisement, though you
 	// might not be able to join.
 	visibility := sg.Spec.Perms[string(access.Read)].In
+	ctx, stop := context.WithCancel(s.ctx)
 	ch, err := idiscovery.AdvertiseServer(ctx, s.discovery, s.svr, "", &sbService, visibility)
-	if err == nil {
-		vlog.VI(4).Infof("sync: advertiseSyncgroupInNeighborhood: successful")
-		cancel := func() {
-			stop()
-			<-ch
-		}
-		s.advSyncgroups[gid] = syncAdvertisementState{cancel: cancel, specVersion: sg.SpecVersion, adId: sbService.Id}
-		return nil
+	if err != nil {
+		stop()
+		return err
 	}
-	stop()
-	return err
+	vlog.VI(4).Infof("sync: advertiseSyncgroupInNeighborhood: successful")
+	cancel := func() {
+		stop()
+		<-ch
+	}
+	s.advSyncgroups[gid] = syncAdvertisementState{cancel: cancel, specVersion: sg.SpecVersion, adId: sbService.Id}
+	return nil
 }
 
 //////////////////////////////