Repository: microsoft/garnet
File: libs/cluster/Server/Gossip.cs (C#)

Code before:

                while (true)
                {
                    var current = currentConfig;
                    var currentCopy = current.Copy();
                    var next = currentCopy.Merge(senderConfig, workerBanList, logger).HandleConfigEpochCollision(senderConfig, logger);
                    if (currentCopy == next) return false;
                    if (Interlocked.CompareExchange(ref currentConfig, next, current) == current)
                        break;
                }
                FlushConfig();
                return true;
            }
            finally
            {
                if (acquireLock) activeMergeLock.ReadUnlock();
            }
        }

        /// <summary>
        /// Run meet background task
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        public void RunMeetTask(string address, int port)
            => Task.Run(() => TryMeetAsync(address, port));

        /// <summary>
        /// This task will immediately communicate with the new node and try to merge the retrieve configuration to its own.
        /// If node to meet was previous in the ban list then it will not be added to the cluster.
        /// </summary>
        /// <param name="address">Address of node to issue meet to</param>
        /// <param name="port"> Port of node to issue meet to</param>
        /// <param name="acquireLock">Whether to acquire lock for merging. Default true</param>
        public async Task TryMeetAsync(string address, int port, bool acquireLock = true)
        {
            GarnetServerNode gsn = null;
            var conf = CurrentConfig;
            var nodeId = conf.GetWorkerNodeIdFromAddress(address, port);
            MemoryResult<byte> resp = default;
            var created = false;

            gossipStats.UpdateMeetRequestsRecv();
            try
            {
                if (nodeId != null)
                    clusterConnectionStore.GetConnection(nodeId, out gsn);

                if (gsn == null)
                {
                    gsn = new GarnetServerNode(clusterProvider, address, port, tlsOptions?.TlsClientOptions, logger: logger);

Review comment (suggestion):
`Task.Run(async () => await TryMeetAsync(...));`

This ensures the outer `Task` represents the full lifecycle of `TryMeetAsync`.

Code after:

                while (true)
                {
                    var current = currentConfig;
                    var currentCopy = current.Copy();
                    var next = currentCopy.Merge(senderConfig, workerBanList, logger).HandleConfigEpochCollision(senderConfig, logger);
                    if (currentCopy == next) return false;
                    if (Interlocked.CompareExchange(ref currentConfig, next, current) == current)
                        break;
                }
                FlushConfig();
                return true;
            }
            finally
            {
                if (acquireLock) activeMergeLock.ReadUnlock();
            }
        }

        /// <summary>
        /// Run meet background task
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        public void RunMeetTask(string address, int port)
            => Task.Run(async () => await TryMeetAsync(address, port));

        /// <summary>
        /// This task will immediately communicate with the new node and try to merge the retrieve configuration to its own.
        /// If node to meet was previous in the ban list then it will not be added to the cluster.
        /// </summary>
        /// <param name="address">Address of node to issue meet to</param>
        /// <param name="port"> Port of node to issue meet to</param>
        /// <param name="acquireLock">Whether to acquire lock for merging. Default true</param>
        public async Task TryMeetAsync(string address, int port, bool acquireLock = true)
        {
            GarnetServerNode gsn = null;
            var conf = CurrentConfig;
            var nodeId = conf.GetWorkerNodeIdFromAddress(address, port);
            MemoryResult<byte> resp = default;
            var created = false;

            gossipStats.UpdateMeetRequestsRecv();
            try
            {
                if (nodeId != null)
                    clusterConnectionStore.GetConnection(nodeId, out gsn);

                if (gsn == null)
                {
                    gsn = new GarnetServerNode(clusterProvider, address, port, tlsOptions?.TlsClientOptions, logger: logger);