简体   繁体   中英

Keep-Alive appears in HTTP header on Debian/Mono - not on Windows

I've been tasked with setting up a ServiceStack based C# application on Debian 7 .

The application is compiled with .NET 4.5.2 and I've installed mono 4.4.2 on Debian (using mono's Debian repository).

The application starts up fine (under it's own user). When I start a client that communicates with that service (using POST, more on that at the end of this question) the client crashes when trying to transmit it's second POST (also 2nd total message to the server).

If I wait ~15 seconds before transmitting the 2nd message it does work. When looking at this with Wireshark it becomes obvious what is happening:

On Debian/Mono a TCP 'FIN/ACK' signal is sent ~15 seconds after the last HTTP message was confirmed by the client (TCP 'ACK'). When looking at the HTTP packages being transmitted I was able to see two things:

  • Keep-Alive appears in the HTTP header ( Keep-Alive: timeout=15,max=100 )
  • The specified HTTPAPI is different ( Mono-HTTPAPI/1.0 )

I don't think the HTTPAPI thing is a problem as I can transmit data just fine if I wait 15 seconds between two POSTs. Due to the 15 seconds thing I'm inclined to believe that the Keep-Alive is the culprit here.

If I transmit data between a Windows/.NET 4.5.2 machine and the same client there is no Keep-Alive flag in the HTTP header and the HTTPAPI reads Microsoft-HTTPAPI/2.0 . Also I can, of course, send multiple POSTs without an exception occuring and without the connection dropping.

I don't know where the Debian/mono machine is pulling that Keep-Alive thing from or how to change it. On most SO questions people are either asked to change their IIS settings (this is self-hosted and on Linux thus this doesn't work, duh) or to set it on the HttpWebRequest (which I don't have access to/isn't there.).

So, my question would be: How do I remove that timeout?

Ah, nearly forgot:

On client site XmlServiceClient.Post(SomeObjectOfClass); is used to transmit a message . Executing that one twice in under 15 seconds causes an ObjectDisposedException to appear, triggered by a not existing/disposed Socket .

On server site WebServiceHost.Init().Start("http://*:1234/"); is used to start the service. A class containing a bunch of Any methods seems to handle creating responses.

It looks like the server closes connection after sending the response (ignoring keep-alive header), while client still thinks that connection is opened and tries to send a message to the closed socket.

To resolve the issue, you can follow the recommended way to install ServiceStack on linux using Nginx+HyperFastCGI. The documentation is available here It's written for Ubuntu linux, but should not be too much different for Debian.

Another option: you can simply install nginx and use it as reverse proxy to your WebServiceHost. In this case you can play with keep-alive settings on server side.

  • You can disable keep-alive for your client Agent at all using keepalive_disable directive (see nginx docs )

  • Limit keep-alive timeout using keepalive-timeout directive (see nginx docs )

  • clear Connection header when send it to WebServiceHost using proxy_set_header Connection ""; directive (see nginx docs )

Also to determine a cause of the issue, it would be great if you provide small reproducible sample, which shows it and tell on which OS your client runs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM