ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 8 forks source link

Batched request service handler is called twice for each given request #251

Closed malat closed 9 years ago

malat commented 9 years ago

If you send 2 request the service handler with be called 4 times... Altought the response will contains only 2 result like expected


[Route("/batch")]
    public class BatchRequest : IReturn<BatchResult>
    {
        public Guid Id { get; set; }
    }

    public class BatchResult
    {
        public Guid Id { get; set; }
    }

    public class BatchService : IService
    {

        private static readonly HashSet<Guid> ReceivedGuids = new HashSet<Guid>();

        public BatchResult Any(BatchRequest request)
        {
            if (ReceivedGuids.Contains(request.Id))
            {
                throw new ArgumentException("Id {0} already received".Fmt(request.Id));
            }

            ReceivedGuids.Add(request.Id);
            return new BatchResult
            {
                Id = request.Id
            };
        }
    }

Failing test

public void IdsShouldNotBeHandleMoreThanOnce()
        {
            var client = new JsonServiceClient("http://localhost:52784/");
            var batch = new[] { new BatchRequest { Id = Guid.NewGuid() }, new BatchRequest { Id = Guid.NewGuid() } };

            var results = client.SendAll(batch);
            var guids = results.Select(r => r.Id);
            Assert.IsTrue(guids.SequenceEqual(batch.Select(b => b.Id)));
        }
mythz commented 9 years ago

I've added this test and an additional test asserting that batched requests are not executed twice which both passes in this commit: https://github.com/ServiceStack/ServiceStack/commit/34de90fdcaaa53e290cefa71fbbec8471fd95b95

I suspect you have another issue in your setup causing this. If not can you re-open this issue with a stand-alone example that repros this issue.

malat commented 9 years ago

Well thanks, you may have fix this with the other commit :) The only other files included in the project is an empty AppHost and the web.config that as been taken from the StarterTemplate Examples

Thanks

malat commented 9 years ago

Another possible option could be that is failing only using asp.net host, on my side the failings is a real integration test using IIS....

mythz commented 9 years ago

Do you have multiple tests and are you clearing the HashSet before each test?

malat commented 9 years ago

Maybe this will help

Here is the raw http request :

POST http://localhost:52784/json/reply/BatchRequest%5B%5D HTTP/1.1 Accept: application/json User-Agent: ServiceStack .NET Client 4.038 Accept-Encoding: gzip,deflate Content-Type: application/json Host: localhost:52784 Content-Length: 85 Expect: 100-continue Connection: Keep-Alive

[{"Id":"b4c6cd2b85874cb999e5d63142fd34a8"},{"Id":"cf0a86a0d7dc46808dfa22eb3995af8e"}]

And the received response :

HTTP/1.1 200 OK Cache-Control: private Content-Type: application/json; charset=utf-8 Vary: Accept Server: Microsoft-IIS/8.0 X-Powered-By: ServiceStack/4.038 Win32NT/.NET X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?RDpcV29ya3NwYWNlc1xQcm90b1xTUy5CYXRjaC5UZXN0QXBwXFRlc3RBcHBcanNvblxyZXBseVxCYXRjaFJlcXVlc3RbXQ==?= X-Powered-By: ASP.NET Date: Sat, 14 Mar 2015 05:53:07 GMT Content-Length: 119

["Id b4c6cd2b-8587-4cb9-99e5-d63142fd34a8 already received","Id cf0a86a0-d7dc-4680-8dfa-22eb3995af8e already received"]

I can send you a zip file if you want

malat commented 9 years ago

https://onedrive.live.com/redir?resid=D182F9119B73C45C!264&authkey=!ADSaXTUmFzNvWrg&ithint=file%2czip

mythz commented 9 years ago

ok cool, just tried it with the latest libs and looks like the issue is now resolved.