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

Reduce close / abort methods in public API #1008

Merged
merged 6 commits into from
Jan 29, 2021

Conversation

bollhals
Copy link
Contributor

Proposed Changes

There are 3 close / abort functions in the public API. This forces a lot of similar implementations in AutorecoveryConnection.
This PR removes all of them except one in the public API and replaces it with extension methods with the same parameters. (This means a recompile should be enough for customers, if they haven't mocked the interface itself)

Types of Changes

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

Checklist

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

@bollhals
Copy link
Contributor Author

bollhals commented Jan 24, 2021

Hmm it works with SDK V 5.0, but build still uses 3.1.x which somehow doesn't like the this.Abort() where Abort is an extension method 🤔
Shall I change it to call the Close method directly, or can we update the SDK?

=> not needed anymore, see comment from @danielmarbach

@michaelklishin
Copy link
Member

michaelklishin commented Jan 25, 2021

There are some known users that mock the connection API interface. I doubt it's a widely used approach but some prominent projects could have adopted it.
Reducing the minimum required API surface here sounds reasonable to me.

@stebet @bording @danielmarbach @lukebakken WDYT?

@michaelklishin
Copy link
Member

Hmm it works with SDK V 5.0, but build still uses 3.1.x which somehow doesn't like the this.Abort() where Abort is an extension method 🤔
Shall I change it to call the Close method directly, or can we update the SDK?

Are there any downsides besides all contributors having to upgrade? I'd say requiring .NET Core 5 for our own development is fine.

@bording
Copy link
Collaborator

bording commented Jan 25, 2021

Reducing the minimum required API surface here sounds reasonable to me.

I'm all for making the Public API simpler, though a quick look at the PR, I'm not quite sure how this PR does that. It seems to just be shuffling the APIs around, not actually reducing anything.

Are there any downsides besides all contributors having to upgrade? I'd say requiring .NET Core 5 for our own development is fine.

It should be perfectly fine to move to a newer SDK because that has no impact on the consumers of the client.

However, something seems off here. I can't think of a reason why the SDK version would impact whether or not the code compiles.

@michaelklishin
Copy link
Member

It reduces the part that is mandatory for implementing. We can consider removing the Abort overload that provide access to the reply code and message. I mean, if you are wiling to force close and ignore all errors, that context is likely not very relevant anyway.

@bollhals
Copy link
Contributor Author

Reducing the minimum required API surface here sounds reasonable to me.

I'm all for making the Public API simpler, though a quick look at the PR, I'm not quite sure how this PR does that. It seems to just be shuffling the APIs around, not actually reducing anything.

The reduction happens at the IConnection and IModel interface. For convenience and to reduce the update effort the existing api are now extension methods.

=> interface smaller, easier to implement it while keeping the public facing api usage the same.

Our benefits are the reduced number of implementation in e.g Connection & AutorecoveringConnection while for the customer nothing changes (except he may calls close now through an extension method)

Are there any downsides besides all contributors having to upgrade? I'd say requiring .NET Core 5 for our own development is fine.

It should be perfectly fine to move to a newer SDK because that has no impact on the consumers of the client.

However, something seems off here. I can't think of a reason why the SDK version would impact whether or not the code compiles.

It is indeed strange, but I have had it happened to me once or twice that they fixed some bug in a newer SDK. This feels just like it.

You can look at the code in question. It's a instance method of e.g. Connection, that calls this.Abort. (This implementing an IConnection and Abort being an extension method on IConnection) So this should be fine, but somehow the old SDK doesn't like it. 🤷‍♂

@bollhals
Copy link
Contributor Author

It reduces the part that is mandatory for implementing. We can consider removing the Abort overload that provide access to the reply code and message. I mean, if you are wiling to force close and ignore all errors, that context is likely not very relevant anyway.

Happy to update it if it's wanted. With this change it's now just deleting the extension method 😊
Keep in mind that through the interface close method customer could still call an abort wirh custom code. So we wouldn't prevent it

@michaelklishin michaelklishin merged commit 572b0fc into rabbitmq:master Jan 29, 2021
@michaelklishin
Copy link
Member

Thank you!

return Close(new ShutdownEventArgs(ShutdownInitiator.Application,
replyCode, replyText),
abort);
_ = CloseAsync(new ShutdownEventArgs(ShutdownInitiator.Application, replyCode, replyText), abort);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to drop the task here because it means we are no longer materializing any exceptions or waiting for the operation to complete

was this only ever called by the upper layers that are now in the extension methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. But I agree that this should probably be fixed in another PR. (I didn't want to mix cleanup and fixing in a pr)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the visibility is why I renamed it to CloseAsync and explicitely dropped the task with _ =. Glad it already worked out😛

@bollhals bollhals deleted the feature/reduce.close.methods branch January 29, 2021 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants