diff --git a/src/Titanium.Web.Proxy/ProxyServer.cs b/src/Titanium.Web.Proxy/ProxyServer.cs index 719256e66..f4a8a3c5d 100644 --- a/src/Titanium.Web.Proxy/ProxyServer.cs +++ b/src/Titanium.Web.Proxy/ProxyServer.cs @@ -777,8 +777,19 @@ private void onAcceptConnection(IAsyncResult asyn) }); } - // Get the listener that handles the client request. - endPoint.Listener!.BeginAcceptSocket(onAcceptConnection, endPoint); + try + { + // based on end point type call appropriate request handlers + // Get the listener that handles the client request. + endPoint.Listener!.BeginAcceptSocket(onAcceptConnection, endPoint); + } + catch (Exception ex) when (ex is ObjectDisposedException || ex is InvalidOperationException) + { + // The listener was Stop()'d, disposing the underlying socket and + // triggering the completion of the callback. We're already exiting, + // so just return. + return; + } }