ClrHttpRequest icon indicating copy to clipboard operation
ClrHttpRequest copied to clipboard

Suggestion: Address possible quantum punishment issue

Open tcartwright opened this issue 1 year ago • 1 comments

I noticed that you are not using the async methods when calling the web services. This can have very nasty effects upon a sql server.

[SQL Server CLR procedures and SQLCLR_QUANTUM_PUNISHMENT](https://dba.stackexchange.com/questions/164891/sql-server-clr-procedures-and-sqlclr-quantum-punishment )

[SQL Server CLR Threading](https://stackoverflow.com/questions/35116558/sql-server-clr-threading)

If the rest api takes a while, or dns takes a long time to resolve then your server will most likely hang as the server tries to punish your api. Sounds weird I know, but trust me from experience. This can be VERY VERY bad.

You really need to either do one of two things:

  • Use Thread.BeginThreadAffinity / Thread.EndThreadAffinity to release the thread management to the OS. Requires UNSAFE.
  • Utilize the async / await operators while periodically calling System.Threading.Thread.Sleep(0); which lets the thread scheduler know you are still alive by releasing your lock on the scheduler.

tcartwright avatar Dec 09 '24 18:12 tcartwright

Hi @tcartwright . I appreciate your concern. However, I don't believe it is necessary, considering the use of the timeout parameter.

EitanBlumin avatar Dec 09 '24 19:12 EitanBlumin