question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] HttpMessage.Properties not accessible anymore after dispose.

See original GitHub issue

Library name and version

Azure.Core 1.30.0

Describe the bug

Hello,

This commit https://github.com/Azure/azure-sdk-for-net/commit/437d4ad07ed5580aa8aac690701c05a62d18049b broke our usage of HttpPipeline in our tests:

We use a fake transport to catch all message sent through the HttpPipeline, then in the asserts we check if the received message are what we are expecting.

With this changes the _propertyBag is disposed and then it’s impossible to access the properties anymore.

Expected behavior

Property should be accessible or we should have a way to copy all of them in the transport layer, maybe with a way to list all keys so we can make a copy of it.

Actual behavior

Property are note available anymore

Reproduction Steps

Capture message with an HttpPipelineTransport and try to access the properties after the Dispose

public class FakeTransport : HttpPipelineTransport
{
	private readonly List<FakeRequest> _requests = new List<FakeRequest>();
	private readonly List<HttpMessage> _receivedMessages = new List<HttpMessage>();
	public IReadOnlyList<HttpMessage> ReceivedMessages => _receivedMessages;
	public IReadOnlyList<FakeRequest> CreatedRequests => _requests;
	public Action<HttpMessage>? OnProcess { get; set; }

	public FakeTransport()
	{
		OnProcess = httpMessage =>
			httpMessage.Response = new FakeResponse(418, "OnProcess must be override in tests that directly need to control the response ");
	}

	public override void Process(HttpMessage message)
	{
		OnProcess?.Invoke(message);
		_receivedMessages.Add(message);
	}

	public override ValueTask ProcessAsync(HttpMessage message)
	{
		OnProcess?.Invoke(message);
		_receivedMessages.Add(message);
		return new ValueTask();
	}

	public override Request CreateRequest()
	{
		var request = new FakeRequest();
		_requests.Add(request);
		return request;
	}
}

Environment

No response

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Socolincommented, Mar 15, 2023

I re-read the code and I saw the overload SetProperty(Type type, object value)

So if I understand correctly, the Dictionary is kind of the “slow” way with string and for performance we should use like a class, and store the property as an object.

So Keys does not really exists, there are 2 kind of keys and since the TypeHandle is stored in one case I think it would be complex to get the list back.

I found a simple way to fix my problem and keep the test as I want them (arrange/act/assert).

Thanks for the explanations.

0reactions
christothescommented, Mar 14, 2023

Yes, there is a dictionary, but it is only referenced inside the array, as you pointed out. Also, this is an internal implementation detail that could also change in the future (as it did in this case ). Unfortunately, the property bag is a resource owned by the type that must be cleaned up on disposal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is this HttpClient usage giving me an "Cannot access ...
The HttpClientHandler will get disposed after the first request. You need to instruct your system not to dispose the handler. Change your using ......
Read more >
Cannot access the 'CustomFields' property of a disposed ...
I have seen some of the tickets raised on this issue and I have the same issue but I don't believe the solutions...
Read more >
Potential Bug: Tensors not being disposed of correctly · ...
js. Describe the expected behavior. I expect to see zero tensors in memory after disposing of them all. Standalone code to reproduce the...
Read more >
Mesh.dispose trigger Uncaught TypeError: Cannot read ...
Hello, When I dispose meshes with mesh.dispose(); disposing meshes give me error: Uncaught TypeError: Cannot read property 'meshes' of null ...
Read more >
41 CFR Part 102-75 -- Real Property Disposal ...
After reaching this determination, the disposal agency must expeditiously make the surplus property available for acquisition by State and local governmental ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found