SocketException:现有连接在IIS 7下被强制关闭,但在IIS下正常运行6

问题描述:

我们已经在IIS 6/Windows Server 2003下运行了几年的.ashx应用程序。我们最近一直试图让一些新的服务器正常运行,并且需要迁移到Win 2k8 R2和IIS 7.5,但是我需要花时间让应用程序在新服务器上运行良好。SocketException:现有连接在IIS 7下被强制关闭,但在IIS下正常运行6

.ashx是一个定制消息队列引擎的Web解释器,我们通过TCP进行对话。因此,在.ashx中,我们创建了一个与消息队列服务器交谈的套接字。这个结构没有发生任何变化,但我得到了赢2K8和IIS 7.5的设置,运行.NET 4的错误,是

System.Net.Sockets.SocketException(0X80004005):现有 连接通过远程主机在 System.Net.Sockets.Socket.Receive被强行关闭(字节[]缓冲区,的Socket 的Socket)

我们不要上了年纪的安装这个错误 - 相同的代码,虽然它运行的是.NET 3.5运行时。

请记住,此错误不是从面向HTTP的套接字引发的,而是从试图与消息队列服务器通信的套接字引发的。我已经证实,我不相信我通过从Web服务器运行“原始”Telnet会话到消息队列并且能够成功地与消息队列交互,从而使防火墙出现问题。

这里是我们如何设置插座:

  this.m_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); 
      System.Net.IPAddress ip = System.Net.IPAddress.None; 

      // Before bothering the DNS server, try to parse numeric IP 
      try 
      { 
       ip = System.Net.IPAddress.Parse(host); 
      } 
      catch (FormatException) 
      { 
       // Not a numeric IP. Do the DNS lookup. 
       // (BTW: DNS lookup will convert the IP, but only after a failing lookup, which is slow) 
       IPHostEntry ipadd = System.Net.Dns.GetHostEntry(host); 
       // (Note: That lookup might fail. It'll throw a SocketException.) 
       ip = ipadd.AddressList[0]; 
      } 
      try 
      { 
       this.m_sock.Connect(ip, port); 
       this.m_sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true); 
       this.m_sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.NoDelay, true); 
       this.m_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1); 
       this.m_sock.ReceiveTimeout = 60 + this.m_timeout; 
       this.m_sock.Blocking = true; 
       this.m_sock.ReceiveBufferSize = 65536; 
       this.m_sock.SendBufferSize = 65536; 
       if (ok != "" && !this.m_isweb) 
       { 
        Console.WriteLine(ok); 
       } 
       break; 
      } 
      catch (SocketException) 
      { 
       this.m_sock.Close(); 
       this.m_sock = null; 
      } 

而现在,在this.m_sock_Receive对我们吹了“ReadSome法”的一个片段:

  if (this.m_sock.Poll(1000000, SelectMode.SelectRead)) 
      { 
       n = this.m_sock.Available; 
       if (n == 0) 
        n = 1;  // Presume at least one byte readable 
       if (max > 0 && n > max) 
        n = max; 
       byte[] buf = new byte[n]; 
       int rcvd = this.m_sock.Receive(buf, SocketFlags.None); 
       if (rcvd == 0) 
        throw new knetmq_Exception(this, "Read EOF", 
         knetmq_Exception.codes.EOF); 

       return buf; 
      } 

之前“接收”发生,有一个“发送”,无一例外地发生,但我没有看到另一边的有效载荷。

任何帮助表示赞赏!

哦,快乐!我修好了它!

它的缺点:我没有设置我的TTL,并且在新服务器上TTL持续超出。

更深入:新服务器碰巧位于略有不同的网络上。因为我们没有设置TTL,所以TTL默认为1.一个wireshark发现TTL被反复超出,所以发出了TCP RST,导致错误被抛出。这就是远程主机从未接收到这些消息的原因。

我在这个问题上敲了我2天的头,所以我希望任何最终得到这个SocketException的人都能看到这个并寻找TTL问题!

+0

活的时间是为了什么? DNS? –

+0

TCP/IP TTL(对不起......当我说TCP RST正在发布时,我的理解被理解了) – longofest