IDocumentStore.JsonRequestFactory.ConfigureRequest event handler - Request always null

250 views
Skip to first unread message

ste...@glimpselive.com

unread,
May 15, 2015, 12:00:23 AM5/15/15
to rav...@googlegroups.com
I'm trying to configure my request timeout in Raven 3.0.3660 with the following code:

            var docStore = new DocumentStore {
                ConnectionStringName = "raven"
            };
            docStore.Initialize();
            docStore.JsonRequestFactory.ConfigureRequest += (sender, args) => {
                if (args.Request != null)
                    args.Request.Timeout = 10 * 60 * 1000;
            };

The problem is that args.Request is always null.  Stepping through the Raven source doesn't help me much; line 88 of HttpJsonRequestFactory.cs always has the request variable as having a value.  Is there a better place I can look to hunt down this bug?

Oren Eini (Ayende Rahien)

unread,
May 15, 2015, 12:05:51 AM5/15/15
to ravendb
Yes, in 3.0, you have the HttpClient there that is used.


Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ste...@glimpselive.com

unread,
May 15, 2015, 8:43:35 AM5/15/15
to rav...@googlegroups.com
The problem this introduces is that since WebRequestEventArgs.Request is never set in line 87 of HttpJsonRequestFactory.cs, it's no longer possible to set the timeout.
The problem with that problem is that the `request` variable in CreateHttpJsonRequest() is of type HttpJsonRequest, not WebRequest.  So I imagine it will take some time to work in a way to make this possible.

Oren Eini (Ayende Rahien)

unread,
May 16, 2015, 12:53:51 PM5/16/15
to ravendb
You get the relevant HTTP Client, so you can customize that.

Barry Hagan

unread,
May 16, 2015, 5:23:55 PM5/16/15
to rav...@googlegroups.com
I've tried to use HttpClient to set the timeout in 3.0 code, but I ended up needing to add a try/catch block due to what appears to be connection sharing of requests (I attempt to set the timeout and eat this invalid operation):

System.InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request.
   at System.Net.Http.HttpClient.set_Timeout(TimeSpan value)
   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   at Raven.Client.Connection.HttpJsonRequestFactory.CreateHttpJsonRequest(CreateHttpJsonRequestParams createHttpJsonRequestParams)
   at Raven.Client.Connection.Async.AsyncServerClient.CreateRequest(String requestUrl, String method, Boolean disableRequestCompression, Boolean disableAuthentication, Nullable`1 timeout)
   at Raven.Client.Connection.Async.AsyncAdminServerClient.<.ctor>b__0(String url, String method)
   at Raven.Client.Connection.AdminRequestCreator.CreateDatabase(DatabaseDocument databaseDocument, RavenJObject& doc)
   at Raven.Client.Connection.Async.AsyncAdminServerClient.<CreateDatabaseAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Raven.Client.Connection.Async.AsyncAdminServerClient.<EnsureDatabaseExistsAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Raven.Client.Extensions.TaskExtensions2.WaitUnwrap(Task task)
   at Raven.Client.Connection.AdminServerClient.EnsureDatabaseExists(String name, Boolean ignoreFailures)

Oren Eini (Ayende Rahien)

unread,
May 17, 2015, 1:57:25 AM5/17/15
to ravendb
A better method would be to set your own documentStore.HttpMessageHandler instance.

Barry Hagan

unread,
May 19, 2015, 7:41:34 PM5/19/15
to rav...@googlegroups.com
Except that when I try to set a HttpMessageHandler on the DocumentStore, it gets disposed by the HttpClient that it is passed to.

Maybe leave that as Func<HttpMessageHandler> on the DocumentStore since that is what is used by HttpJsonRequestFactory:

Or pass the appropriate flag to not dispose the handler when constructing a new HttpClient (assuming it is safe to reuse):



This is the result of trying to set a HttpMessageHandler on DocumentStore right now:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.WebRequestHandler'.
   at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Raven.Client.Connection.Implementation.HttpJsonRequest.<>c__DisplayClass13.<<SendRequestInternal>b__12>d__15.MoveNext()

Oren Eini (Ayende Rahien)

unread,
May 20, 2015, 4:06:42 PM5/20/15
to ravendb
No, this is the same HttpMessageHandler that you set on the document store.
You just need to make sure to set it _before_ calling Initialize();

Barry Hagan

unread,
May 20, 2015, 6:35:01 PM5/20/15
to rav...@googlegroups.com
Ok, let me know what is wrong with the attached failing test.
CustomHttpMessageHandler.cs

Oren Eini (Ayende Rahien)

unread,
May 21, 2015, 8:33:51 AM5/21/15
to ravendb
You are correct, I'm sorry about this. I've changed this to use a lambda factory, instead of a single instance.
See next build.
Reply all
Reply to author
Forward
0 new messages