NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.15k stars 1.47k forks source link

never return a result to the client broswer when I kill the request thread in code before the execution of method is finished #2950

Open w281015308 opened 5 years ago

w281015308 commented 5 years ago

Prerequisites

Description

image

image

image

but the codes I added just for testing. It is not really correct.

System Configuration

robertbissonnette commented 5 years ago

I gotta ask. What exactly is your use case with this?

Normal operation would not have you killing threads in the context of the server to begin with. But in your scenario you are actually killing threads that below to the thread pool. If you want to terminate the execution and return a response to the caller, then you should either use an async model with a cancellationToken or throw an exception.

w281015308 commented 5 years ago

I gotta ask. What exactly is your use case with this?

Normal operation would not have you killing threads in the context of the server to begin with. But in your scenario you are actually killing threads that below to the thread pool. If you want to terminate the execution and return a response to the caller, then you should either use an async model with a cancellationToken or throw an exception.

Yes, I really want to terminate the execution. I have a circuit breaker to limit the concurrent request and it is working in another thread. when the threshold value of concurrent request is reached, circuit breaker can not throw an exception in the request thread. so kill the request thread is simple. Cause our scenario is very complex, I have to do that. If I change Nancy code for throwing an exception when the request thread is killed, It is correct or not? Thanks for your reply. :)