javaspring-boothttpspring-mvcspring-restcontroller

Spring @RestController and @PathVariable queuing bug?


I've noticed some odd behavior with my SpringBoot micro service. I'm using spring mvc, springboot 3.3.3 and Java 21.

Consider the following code in a Controller (annotated with @RestController and lombok's @Slf4j):

@GetMapping("/test/{id}")
public void getTest(@PathVariable Integer id) {
  log.info("get test: {}", id);
}

@DeleteMapping("/test/{id}")
public void deleteTest(@PathVariable Integer id) throws InterruptedException  {
  TimeUnit.SECONDS.sleep(10);
  log.info("delete test: {}", id);
}

@GetMapping("/test/{id}/something")
public void getTestSomething(@PathVariable Integer id) throws InterruptedException {
  TimeUnit.SECONDS.sleep(10);
  log.info("get test something: {}", id);
}

If I hit DELETE /test/3 followed by GET /test/3 within 10 seconds, the GET will wait until the DELETE request returns. However if I hit GET /test/3/something and then GET /test/3 it won't wait. The latter is the behavior I would expect for both.

Also, if I do a different id for DELETE and the first GET, the GET won't wait. For example, DELETE /test/4 followed by GET /test/3

Another interesting observation is that if I don't use the passed in path variable, e.g. just don't log it or pass it to anything, it won't wait. The same goes if the paths don't specify path variables and are equal. E.g: GET /test and DELETE /test

Also, if I include a @RequestParameter the waiting issue doesn't occur. E.g. GET /test/3?key=value

Is the weird waiting behavior I've observed expected? Or have I uncovered some strange bug?


Solution

  • Turns out that the problem was how I was making the queries. I was using Swagger UI.