Bug 40039 - Memory leaks in WCF Duplex Channel in Mono
Summary: Memory leaks in WCF Duplex Channel in Mono
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 4.0.0
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-04-01 08:21 UTC by Ashish
Modified: 2016-12-06 16:19 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Ashish 2016-04-01 08:21:07 UTC
I am Creating a Server Client Application in which I am using TCP binding with Duplex Channel There is a method Poll() in Server App and CallBack method OnPollBack() in Client app. I am calling Poll method by client app in 100 millisecond but in half an hour I am getting out of memory exception. This Duplex Tcp binding takes 10 mb in around 200 hits of Poll method now What I do there is a lot of memory leak in Tcp binding of wcf..


Server Code:

public class SipServer { private ServiceHost sipHost; public void HostServer() {

        var address = @"net.tcp://localhost:44000/SipPhone";

        var sipPhImpl = new SipPhoneImpl();
        sipHost = new ServiceHost(sipPhImpl);

        var tcpBinding = new NetTcpBinding(SecurityMode.None);
        tcpBinding.ReceiveTimeout = TimeSpan.MaxValue;
        tcpBinding.SendTimeout = TimeSpan.MaxValue;

        var sipEndPoint = sipHost.AddServiceEndpoint(typeof(ISipPhone), tcpBinding, address);
        sipHost.Open();
    }

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class SipPhoneImpl : ISipPhone
    {

        private ISipPhoneCallback _phCallBack = null;
        private bool disposed = false;


        public int Poll(bool sendBack, string pollStr)
        {
            if (sendBack)
            {
                try
                {
                    ISipPhoneCallback cb = _phCallBack != null
                                                    ? _phCallBack
                                                    : OperationContext.Current.GetCallbackChannel<ISipPhoneCallback>();
                    if (cb != null)
                    {
                        cb.OnPollBack(pollStr);
                    }
                }
                catch (Exception ex)
                {

                    return 1;
                }
            }

            return 0;
        }

    }
}


Client Code:

public class UcomClient { private ISipPhone m_sipPhone; public void CreateClient() {

        var hostAddress = @"net.tcp://localhost:44000/SipPhone";

        var tcpBinding = new NetTcpBinding(SecurityMode.None)
        {
            ReceiveTimeout = TimeSpan.MaxValue,
            SendTimeout = TimeSpan.MaxValue

        };

        InstanceContext cbContext = new InstanceContext(new UCOMSipCallBack());
        var spFactory = new DuplexChannelFactory<ISipPhone>(cbContext,tcpBinding, hostAddress);
        m_sipPhone = spFactory.CreateChannel();

    }

    public int Poll(bool sendBack, string pollStr)
    {
        try
        {
            return m_sipPhone.Poll(sendBack, pollStr);
        }
        catch (Exception ex)
        {

            return 1;
        }
    }
}

public class UCOMSipCallBack : ISipPhoneCallback
    {
        public void OnPollBack(string pollStr)
        {
            Console.WriteLine(pollStr + " : " + DateTime.Now);

        }
    }




Interfaces:

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ISipPhoneCallback))] public interface ISipPhone { [OperationContract(IsInitiating = true)] int Poll(bool sendBack, string pollStr); }

public interface ISipPhoneCallback { [OperationContract(IsOneWay = true)] void OnPollBack(string pollStr);

}

Note You need to log in before you can comment on or make changes to this bug.