Skip to content

Conversation

@maxkoshevoi
Copy link
Contributor

@maxkoshevoi maxkoshevoi commented Feb 11, 2022

Quick follow-up to #63767

While annotating Microsoft.Extensions.Logging, it turns out that IOptionsMonitor.OnChange could return null:
https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Logging/src/StaticFilterOptionsMonitor.cs#L16

@ghost
Copy link

ghost commented Feb 11, 2022

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost added area-Extensions-Options new-api-needs-documentation community-contribution Indicates that the PR has been added by a community member labels Feb 11, 2022
@ghost
Copy link

ghost commented Feb 11, 2022

Tagging subscribers to this area: @dotnet/area-extensions-options
See info in area-owners.md if you want to be subscribed.

Issue Details

Quick follow-up for #63767

While annotating Microsoft.Extensions.Logging, it turns out that IOptionsMonitor.OnChange could return null:
https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Logging/src/StaticFilterOptionsMonitor.cs#L16

Author: maxkoshevoi
Assignees: -
Labels:

new-api-needs-documentation, area-Extensions-Options

Milestone: -

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

Copy link
Contributor

@deeprobin deeprobin left a comment

Choose a reason for hiding this comment

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

LGTM

@stephentoub
Copy link
Member

stephentoub commented Feb 12, 2022

Is that the only case? Is it likely others have implemented this to return null? Do we document it as possibly returning null?

If this is an isolated case, seems better to fix that one occurrence to not return null; basically it was violating the implicit contract and we're fixing it. It's weird / unexpected for something that returns IDisposable to return null. It could just return a dummy singleton that nops.

@maxkoshevoi
Copy link
Contributor Author

@stephentoub documentation doesn't say about nullability of the result, but all Extensions.Logging.* assemblies treat it as being nullable.

Not sure about other places that implement IOptionsMonitor

@stephentoub
Copy link
Member

but all Extensions.Logging.* assemblies treat it as being nullable

Meaning all consumers do null checks on the result?

Sounds then like nullable is the right answer.

Thanks

@eerhardt
Copy link
Member

Meaning all consumers do null checks on the result?

Yes. Every place I inspected does null checks before disposing the result. Examples:

_changeTokenRegistration?.Dispose();

https://github.com/dotnet/aspnetcore/blob/38bd273d7887dfb408f407d5f6db0d70a8b75e99/src/Logging.AzureAppServices/src/BatchingLoggerProvider.cs#L181

@eerhardt eerhardt merged commit 7aae884 into dotnet:main Feb 12, 2022
@maxkoshevoi maxkoshevoi deleted the mk/fix-options branch February 12, 2022 18:07
@maxkoshevoi
Copy link
Contributor Author

Off-topic: @eerhardt could you please tell, how do you do code previews like this?
image

@eerhardt
Copy link
Member

eerhardt commented Feb 12, 2022

how do you do code previews like this?

It only works for code in the same repo. But the way I do it is using Copy permalink in this context menu:

image

Then when you paste that link into GH, it shows the code.

/// <inheritdoc />
public void Dispose()
{
_optionsReloadToken?.Dispose();
_messageQueue.Dispose();
}

Your links above are using a branch name, not a commit hash. So in the future, when the code changes, those links will point to different code, whatever happens to be at that line in the future. Using "permalink", or commit hash links, will always point to that code, even if it is deleted in the future.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-Options community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants