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

Improve GracefulStop() analyzer and code fix #60

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

Arkatufus
Copy link
Contributor

Changes

Make sure that the GracefulStop() method being invoked are defined inside GracefulStopSupport static class and not a custom method defined by the user.

Copy link
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

Self review

Comment on lines +129 to +145
public MyActor()
{
ReceiveAsync<string>(async str =>
{
await GracefulStop(TimeSpan.FromSeconds(3));
});

ReceiveAnyAsync(async _ =>
{
await GracefulStop(TimeSpan.FromSeconds(3));
});
}

public Task GracefulStop(TimeSpan timeout)
{
return Task.CompletedTask;
}
Copy link
Contributor Author

@Arkatufus Arkatufus Jan 23, 2024

Choose a reason for hiding this comment

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

We're not responsible for these kind of shenanigans.

Copy link
Member

Choose a reason for hiding this comment

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

100%.

Comment on lines +64 to +65
return methodSymbol is { Name: "GracefulStop", IsExtensionMethod: true }
&& SymbolEqualityComparer.Default.Equals(methodSymbol.ContainingType, akkaContext.AkkaCore.GracefulStopSupportType);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This checks that the method in question is defined within the GracefulStopSupport static class.

return;

var diagnostic = Diagnostic.Create(RuleDescriptors.Ak1002DoNotAwaitOnGracefulStop, awaitExpression.GetLocation());
ctx.ReportDiagnostic(diagnostic);
}, SyntaxKind.InvocationExpression);
}

private static bool IsInsideReceiveAsyncLambda(SyntaxNode node, SemanticModel semanticModel, AkkaContext akkaContext)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Method is moved to CodeAnalysisExtensions.cs, will be used by other analyzers.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, great idea.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Very well done

Comment on lines +129 to +145
public MyActor()
{
ReceiveAsync<string>(async str =>
{
await GracefulStop(TimeSpan.FromSeconds(3));
});

ReceiveAnyAsync(async _ =>
{
await GracefulStop(TimeSpan.FromSeconds(3));
});
}

public Task GracefulStop(TimeSpan timeout)
{
return Task.CompletedTask;
}
Copy link
Member

Choose a reason for hiding this comment

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

100%.

return;

var diagnostic = Diagnostic.Create(RuleDescriptors.Ak1002DoNotAwaitOnGracefulStop, awaitExpression.GetLocation());
ctx.ReportDiagnostic(diagnostic);
}, SyntaxKind.InvocationExpression);
}

private static bool IsInsideReceiveAsyncLambda(SyntaxNode node, SemanticModel semanticModel, AkkaContext akkaContext)
Copy link
Member

Choose a reason for hiding this comment

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

Yes, great idea.

@Aaronontheweb Aaronontheweb merged commit 3ee9ca2 into akkadotnet:dev Jan 23, 2024
2 checks passed
@Arkatufus Arkatufus deleted the AK1002-improve-GracefulStop branch January 25, 2024 18:29
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.

2 participants