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

Missing ConfigureAwait in TcpClientAdapter #897

Merged
merged 1 commit into from
Jul 7, 2020

Conversation

danielmarbach
Copy link
Collaborator

Proposed Changes

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • 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

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • 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

Further Comments

@bording I also saw this

#if NET461
            await Task.Run(() => _sock.Connect(ep, port)).ConfigureAwait(false);
#else
            await _sock.ConnectAsync(ep, port).ConfigureAwait(false);
#endif

any reasons why we are not using

#if NETFRAMEWORK
            await Task.Run(() => _sock.Connect(ep, port)).ConfigureAwait(false);
#else
            await _sock.ConnectAsync(ep, port).ConfigureAwait(false);
#endif

and then what I also wondered is if the else case ever exists? I can't find that method overload. Judging by the history it started with

https://github.com/rabbitmq/rabbitmq-dotnet-client/blame/696ed9be4e337f8472b32f85bd95bc46a48ca781/projects/client/RabbitMQ.Client/src/client/impl/TcpClientAdapter.cs#L35-L39

Any ideas? Something seems off

@bording
Copy link
Collaborator

bording commented Jul 7, 2020

@danielmarbach The else case is an extension method from the SocketTaskExtensions class which is in net471+. That's why the ifdef is currently targeting net461. If the target framework is changed/updated, the new method will be used even if the ifdef was overlooked.

@michaelklishin michaelklishin merged commit 849b9b8 into rabbitmq:master Jul 7, 2020
@danielmarbach danielmarbach deleted the tcpclientadapter branch July 10, 2020 13:36
@@ -27,7 +27,7 @@ public virtual async Task ConnectAsync(string host, int port)
throw new ArgumentException($"No ip address could be resolved for {host}");
}

await ConnectAsync(ep, port);
await ConnectAsync(ep, port).ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any difference in using ConfigureAwait(false) at the end of the method? After all, after this line there is no code and there is no next step of the state machine. Or am I missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no difference. Context capturing is applied to the continuation which is the end of the method. Though in general libs that don't need context capture should always opt out for every await. It would be best to even enable i.ex. Fxcop even if only https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2007?view=vs-2019 is activated

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Also I use ca2007 in everyday work. I have to always disable its warnings for test projects.

@lukebakken lukebakken mentioned this pull request Jul 13, 2020
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