1

Suppose we have a spring rest controller that does a long operation:

@PostMapping(path = "someLongOperation")
public ResponseEntity<?> doOp(@RequestBody MyBody) {
   ...do A
   ...do B //client cancels request while execution is at this step
   ...do some calculations
   ...save result to database
   return ResponseEntity.ok("my response body")
}

And at step B client cancels the request, eg. pressing cancel on Postman, closing web page on browser, will our method still continue executing and write the results to the database?

And are asynchronous methods different in this regard?

@PostMapping(path = "someLongOperation")
public Callable<ResponseEntity<?>> doOp(@RequestBody MyBody) {
   return () -> {
      ...do A
      ...do B //client cancels request while execution is at this step
      ...do some calculations
      ...save result to database
      return ResponseEntity.ok("my response body")
  }
}
uylmz
  • 1,480
  • 2
  • 23
  • 44
  • does this answer your question: https://stackoverflow.com/questions/2652082/can-a-http-server-detect-that-a-client-has-cancelled-their-request – JoSSte Apr 29 '20 at 16:16
  • 1
    yes execution will continue, when client cancels the request it just means that client does not care about the result of the api – arshid dar Apr 29 '20 at 16:16

0 Answers0