Bug 25698 - WCF REST service hangs for PUT requests
Summary: WCF REST service hangs for PUT requests
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-01-04 02:20 UTC by SJ
Modified: 2017-09-06 16:55 UTC (History)
5 users (show)

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

minimal sample to reproduce problem (1.41 KB, text/plain)
2015-06-25 17:33 UTC, Tom

Description SJ 2015-01-04 02:20:58 UTC
WCF REST service has been decorated with the Put method. When sending a request, it hangs where the service doesn't even see the request come through

[WebInvoke(UriTemplate = "Add", Method = WebRequestMethods.Http.Put, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped)]
        public int Add(int i)
            Console.WriteLine("Inside Add");
            return i + count;

PUT http://XXXX/Add HTTP/1.1
Accept: application/json
Content-Type: application/json
Connection: Keep-Alive
Pragma: no-cache
Content-Length: 6


Interestingly the same method is processed when I change the client uses POST as the METHOD Type.

POST http://XXXX/Add HTTP/1.1
Accept: application/json
Content-Type: application/json
Connection: Keep-Alive
Pragma: no-cache
Content-Length: 6


HTTP/1.1 200
Content-Type: application/xml; charset=utf-8
Server: Mono-HTTPAPI/1.0
Date: Sun, 04 Jan 2015 07:17:00 GMT
Content-Length: 77
Keep-Alive: timeout=15,max=100

<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">121112</int>
Comment 1 Tom 2015-06-25 15:35:50 UTC
Experiencing the same results, for any verb except GET or POST. PUT, DELETE, OPTIONS, and custom verbs (tested via curl -X) all result in a hung thread and no-response.

Mono version is build from tarball 4.0.2 (.5/c99aa0c), also can reproduce with 3.2.8 (also from tarball).

I'm doing trivial self-hosting using WCF REST, webHttpBinding, <webHttp />, ServiceHost(). My method looks like:


But this seems irrelevant, because no matter which URI I request, if it is within the web app root and uses a verb other than GET or POST, it hangs.
Comment 2 Tom 2015-06-25 16:39:26 UTC
(Argh, waited too long and can't update my previous comment!)

Tracing the Chanels.Http namespace, it looks like the HttpChannelListener accepts the connection, calls TryDequeueRequest and... just stays there? Because the tracing stops there unless I kill the app.

[0x7fe88698c700: 8.81124 0] LEAVE: System.ServiceModel.Channels.Http.HttpChannelListener`1:OnAcceptChannel (System.TimeSpan)(unknown return type 13)
[0x7fe88698c700: 8.81213 0] ENTER: System.ServiceModel.Channels.Http.HttpReplyChannel:OnOpen (System.TimeSpan)(this:0x7fe8970ec9b8[System.ServiceModel.Channels.Http.HttpReplyChannel dcfdistributionserver.exe], [], )
[0x7fe88698c700: 8.81222 0] LEAVE: System.ServiceModel.Channels.Http.HttpReplyChannel:OnOpen (System.TimeSpan)
[0x7fe88698c700: 8.81234 0] ENTER: System.ServiceModel.Channels.Http.HttpReplyChannel:TryReceiveRequest (System.TimeSpan,System.ServiceModel.Channels.RequestContext&)(this:0x7fe8970ec9b8[System.ServiceModel.Channels.Http.HttpReplyChannel dcfdistributionserver.exe], [], [BYREF:0x7fe8970ed070], )
[0x7fe88698c700: 8.81237 1] ENTER: System.ServiceModel.Channels.Http.HttpListenerManager:TryDequeueRequest (System.ServiceModel.Dispatcher.ChannelDispatcher,System.TimeSpan,System.ServiceModel.Channels.Http.HttpContextInfo&)(this:0x7fe8970e0878[System.ServiceModel.Channels.Http.HttpStandaloneListenerManager dcfdistributionserver.exe], [System.ServiceModel.Dispatcher.ChannelDispatcher:0x7fe89706d0f8], [], [BYREF:0x7fe88698b700], )

And this is the last we hear from thread 8c700.
Comment 3 Tom 2015-06-25 17:33:42 UTC
Created attachment 11742 [details]
minimal sample to reproduce problem

dmcs -r:System.ServiceModel -r:System.ServiceModel.Web hangdemo.cs -out:hangdemo.exe

mono hangdemo.exe <-- in another window

curl http://localhost:8083/ep/item/bar

>> Prints "bar"

curl DELETE http://localhost:8083/ep/item/bar <-- or any url 

>> hangs forever
Comment 4 Ernestas 2016-03-04 08:29:39 UTC
I have the same problem on 

Mono JIT compiler version 4.2.1
Raspbian GNU/Linux 8 \n \l

I can confirm that the request didn't reach Custom MessageEncoder, ReadMessage method, and response is only returned after the service is killed. Only GET, POST Methods work.
Comment 5 jcde 2016-08-02 15:29:05 UTC
The fix should be in HttpReplyChannel.cs

if (ctxi.Request.HttpMethod == "POST" || ctxi.Request.HttpMethod == "PUT" )
    msg = CreatePostMessage (ctxi);
else if (ctxi.Request.HttpMethod == "GET" || ctxi.Request.HttpMethod == "DELETE" || ctxi.Request.HttpMethod == "OPTIONS")
    msg = Message.CreateMessage (MessageVersion.None, null);


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