Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hub] Small improvements & refactorings #29952

Merged
merged 5 commits into from
Jul 20, 2022

Conversation

danielmarbach
Copy link
Contributor

Contributing to the Azure SDK

Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.

For specific information about pull request etiquette and best practices, see this section.

@ghost ghost added Event Hubs customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Jul 18, 2022
@ghost
Copy link

ghost commented Jul 18, 2022

Thank you for your contribution @danielmarbach! We will review the pull request and get back to you soon.

@ghost ghost added the Community Contribution Community members are working on the issue label Jul 18, 2022
@danielmarbach
Copy link
Contributor Author

@jsquire I noticed GetPooledProducer might call TransportProducerFactory multiple times because GetOrAdd might call the value factory multiple times. Maybe it is not a problem I just made me suspicious because the transport producer is a resource that needs to be closed if I understand the code correctly.

@danielmarbach
Copy link
Contributor Author

Please also see #29952 (comment)

@danielmarbach
Copy link
Contributor Author

Ah I think these comments

// A race condition at this point may end with CloseAsync called on
            // the returned PoolItem if it had expired. The probability is very low and
            // possible exceptions should be handled by the invoking methods.

// If TryRemove returned false the PoolItem would not be closed deterministically
                // and the ExpirationTimer callback would eventually remove it from the
                // Pool leaving to the Garbage Collector the responsibility of closing
                // the TransportProducer and the AMQP link.

explains things

@danielmarbach
Copy link
Contributor Author

I have another design related question. I wonder if it would make sense to add the necessary state and references to PooledProducer and then make the DisposeAsync method do the cleaning. With that the pooled producer could have a reference to the PooledItem and piggy back the identifier and what is needed for the cleanup. While this class is a bit sneaky how it reaches into the parent state it would get rid of the unnecessary closure.

@jsquire
Copy link
Member

jsquire commented Jul 19, 2022

I have another design related question. I wonder if it would make sense to add the necessary state and references to PooledProducer and then make the DisposeAsync method do the cleaning. With that the pooled producer could have a reference to the PooledItem and piggy back the identifier and what is needed for the cleanup. While this class is a bit sneaky how it reaches into the parent state it would get rid of the unnecessary closure.

I generally have a strong preference to keep object graphs flowing in a single direction, but this is an internal construct of very tightly coupled types, so I'm not totally opposed in this specific instance. I do know that we originally ran into a lot of issues with concurrent use and non-deterministic clean-up that we had to guard against. (the two comments that you highlighted call some out)

Do you think we'd be opening up additional corner cases to guard against?

@danielmarbach
Copy link
Contributor Author

I guess this is good to go then

@jsquire jsquire merged commit 0eea752 into Azure:main Jul 20, 2022
@jsquire
Copy link
Member

jsquire commented Jul 20, 2022

I guess this is good to go then

Much appreciated!

@danielmarbach danielmarbach deleted the event-hub branch July 21, 2022 19:33
sofiar-msft pushed a commit to sofiar-msft/azure-sdk-for-net that referenced this pull request Dec 7, 2022
* Provide dictionary count during map creation

* Remove unnecessary string during ActiveInstances management

* Remove LINQ

* Remove Task.Completed

* Remove unnecessary paranthesis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Event Hubs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants