{"action":"opened","issue":{"url":"https://api.github.com/repos/OData/WebApi/issues/102","labels_url":"https://api.github.com/repos/OData/WebApi/issues/102/labels{/name}","comments_url":"https://api.github.com/repos/OData/WebApi/issues/102/comments","events_url":"https://api.github.com/repos/OData/WebApi/issues/102/events","html_url":"https://github.com/OData/WebApi/issues/102","id":54014610,"number":102,"title":"OData BatchHandler starts and ends batch request on different threads.","user":{"login":"LianwMS","id":9375712,"avatar_url":"https://avatars.githubusercontent.com/u/9375712?v=3","gravatar_id":"","url":"https://api.github.com/users/LianwMS","html_url":"https://github.com/LianwMS","followers_url":"https://api.github.com/users/LianwMS/followers","following_url":"https://api.github.com/users/LianwMS/following{/other_user}","gists_url":"https://api.github.com/users/LianwMS/gists{/gist_id}","starred_url":"https://api.github.com/users/LianwMS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LianwMS/subscriptions","organizations_url":"https://api.github.com/users/LianwMS/orgs","repos_url":"https://api.github.com/users/LianwMS/repos","events_url":"https://api.github.com/users/LianwMS/events{/privacy}","received_events_url":"https://api.github.com/users/LianwMS/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-12T02:07:52Z","updated_at":"2015-01-12T02:07:52Z","closed_at":null,"body":"HttpBatchHandler starts and ends bacth request on different threads.  \n  \nAssume, you create batching request (BR), including 2 change-sets (CS1, CS2).  \n  \nSo, OData batching handler will process BR in this sequence:  \n\n  1. Receive BR on thread 1 \n  2. Split BR into child requests: CS1, CS2 \n  3. BeginExecute child requests sequentially \n  4. Process CS1 in thread 2 \n  5. Process CS2 in thread 2 \n  6. End BR on thread (!!!) 2   \n\nYou can intercept these events on ProcessRequest/ProcessResponse methods of\ncustom MessageProcessingHandler. Just output current thread ID in your\nCustomMessageProcessingHandler.ProcessRequest/ProcessResponse.  \n  \nI posted question on StackOverflow: [\nhttp://stackoverflow.com/questions/23614917/webapi-odata-batch-request-starts-\nand-end-on-different-threads-how-avoid\n](http://stackoverflow.com/questions/23614917/webapi-odata-batch-request-\nstarts-and-end-on-different-threads-how-avoid)  \n  \nAnd I added attachment, which contains solution with 2 projects: web-server\nand console client. Just run them simultaneously and web-server will create\nfile D:\\expreiment.txt, with content  \n\n    \n    \n    Setup server\n    ENTER: request: http://localhost:61562/odata/$batch, thread: 8 <== batch request should end on thread 8\n    ENTER: request: http://localhost:61562/odata/Persons, thread: 11\n    Create dfwerg, by thread 11\n    EXIT:  request: http://localhost:61562/odata/Persons, thread: 11\n    ENTER: request: http://localhost:61562/odata/Persons, thread: 11\n    Create dfwerg, by thread 11\n    EXIT:  request: http://localhost:61562/odata/Persons, thread: 11\n    EXIT:  request: http://localhost:61562/odata/$batch, thread: 11 <== it's not ok\n\nThese messages are created by message handler.  \n  \nI think its a bug, batch request should end on same thread, where it was\nstarted. Users cannot surround batch request by transaction\n(System.Transactions.Transaction, for example)  \n\nWork Item Details\n--------------------\n**Original CodePlex Issue:**\t[Issue 1940](http://aspnetwebstack.codeplex.com/workitem/1940)\n**Status:**\tProposed\n**Reason Closed:**\tUnassigned\n**Assigned to:**\tUnassigned\n**Reported on:**\tMay 13, 2014 at 3:21 PM\n**Reported by:**\tcatahoc\n**Updated on:**\tJun 11, 2014 at 8:03 PM\n**Updated by:**\tadamcaviness\n\n\n#### Binary Attachments\n\n[codeplex.sample.7z](http://aspnetwebstack.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=aspnetwebstack&WorkItemId=1940&FileAttachmentId=842493)"}}