Skip to content

Infinite increment of methods-jitted-count counter when using a rule for a full request. #2168

@sergey-rubtsov-05

Description

@sergey-rubtsov-05

FluentValidation version

11.8.0

ASP.NET version

.NET 7

Summary

I met with a strange issue. methods-jitted-count counter increments infinitely if a project has a rule for a full request (not for a property of the request). And it is the only problem, I didn't notice problems with performance or something else.

The first time I saw the problem in my work project which worked with 80 RPS. But I also reproduce the problem in the example project.

Steps to Reproduce

  1. Create a request with at least one property
public record Request(int? Property);
  1. Create a validator with a rule for the request, not for property of request
public class RequestValidator : AbstractValidator<Request>
{
    public RequestValidator() =>
        RuleFor(request => request)
            .Must((request) => request.Property.HasValue);
}
  1. Register the validator as a scoped service
builder.Services.AddScoped<IValidator<Request>, RequestValidator>();
  1. Create a controller with the injected validator and a method which uses it
[ApiController]
[Route("[controller]/[action]")]
public class ExampleController : ControllerBase
{
    private readonly IValidator<Request> _requestWithProblemValidator;

    public ExampleController(IValidator<Request> requestWithProblemValidator) =>
        _requestWithProblemValidator = requestWithProblemValidator;

    [HttpPost]
    public IActionResult Problem(Request request) =>
        _requestWithProblemValidator.Validate(request).IsValid ? Ok() : BadRequest();
}
  1. Start the application
  2. Start monitoring of methods-jitted-count counter in a terminal with the command. On my computer, it shows: Number of Methods Jitted - 1,830
dotnet-counters monitor -p {PID of the ASP.NET application} --counters System.Runtime[methods-jitted-count]
  1. Execute the request 100 times for warming up. Now the counter shows: Number of Methods Jitted - 2,311
  2. Execute the request 100 times to demonstrate the problem. The counter shows: Number of Methods Jitted - 2,411
  3. Execute one more iteration. The counter: Number of Methods Jitted - 2,512. The counter will continue increment for every call.

Expected result

  1. Update the validator code with a rule for a property of request.
public class RequestValidator : AbstractValidator<Request>
{
    public RequestValidator() =>
        RuleFor(request => request.Property)
            .Must((request, _) => request.Property.HasValue);
}
  1. Start the application
  2. Start monitoring of methods-jitted-count counter in a terminal with the command. On my computer, it shows: Number of Methods Jitted - 1,815
  3. Execute the request 100 times for warming up. Now the counter shows: Number of Methods Jitted - 2,229
  4. Execute the request 100 times to demonstrate that the problem does not reproduce. The counter shows: Number of Methods Jitted - 2,229

Also, I attached the project which I used to demonstrate the problem.
FluentValidationMethodJittedProblem.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions