-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Please provide the following (and please check them off the list with [x]) before submitting this issue:
- Expected behavior. Please provide links to the specific Microsoft Graph documentation you used to determine the expected behavior.
- Actual behavior. Provide error codes, stack information, and a Fiddler capture of the request and response (please remove personally identifiable information before posting).
- Steps to reproduce the behavior. Include your code, IDE versions, client library versions, and any other information that might be helpful to understand your scenario.
Expected behavior
Documentation of GraphClientFactory.Create() method does not describe disposal of passed handlers, eg the collection of DelegatingHandler and optional finalHandler.
IMO, passing disposable objects to another object does not imply that the receiving object can take ownership of those disposable objects. However changing the behavior is breaking, and adding an additional optional argument to control dispose behavior may not be desirable. So maybe this is basically just a documentation issue.
Actual behavior
Currently the method creates a HttpClient that disposes its HttpMessageHandler and thus the collection of DelegatingHandler and optional finalHandler as the HttpClient is created without specifying the bool disposeHandler parameter.
Steps to reproduce the behavior
A test that shows finalHandler is disposed:
[Fact]
public void CreateClient_WithFinalHandlerDisposesTheFinalHandler()
{
var finalHandler = new MockHttpHandler();
using (HttpClient client = GraphClientFactory.Create(handlers: GraphClientFactory.CreateDefaultHandlers(testAuthenticationProvider.Object), finalHandler: finalHandler))
{
Assert.NotNull(client);
}
Assert.True(finalHandler.Disposed);
}
private class MockHttpHandler : HttpMessageHandler
{
public bool Disposed;
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
protected override void Dispose(bool disposing)
{
Disposed = true;
base.Dispose(disposing);
}
}