惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - stone

release 版本dll的调试 Excel C# Automation 如何让iframe 自动适应窗口的高度 自定义Silverlight toolkit 里面的 Column Chart 的data point 二叉树算法题 How to do live debug the Managed code in Windows Phone 7 单链表操作相关算法 BUG: "Old format or invalid type library" error when automating Excel on 64 bit server 2008 - stone enable Assembly Load Trace 不合法的XML字符必须被替换为相应的实体 - stone - 博客园 如何修改 VS 自动生成的 COM interop dll VS中Sos调试扩展简介 (转帖) Sql server 2005 connection string - stone Get depth of BTree Quick sort C# code(2) Quick sort C# code use the network trace, from msdn. - stone 字节流编码获取原来这么复杂,但也很简单 通过DataTable获得表的主键 让IE支持自己的协议
dead lock in thread pool
stone · 2012-08-10 · via 博客园 - stone

The Problem

A common problem in .NET applications is a deadlock in the ThreadPool. This deadlock in the threadpool is usually manifested by requests timing out (in particular Http requests, but this might happen pretty much anywhere).

The source of the problem is the ThreadPool. The ThreadPool is a mechanism in the .NET Framework to minimize thrashing due to excesive number of concurrent threads. This is done by exposing an API that allows programmers to queue tasks on the ThreadPool that has a cap on the number of running threads. The tasks are dispatched to the threads until the cap is reached, any remaining tasks are placed on a queue and they wait for a thread from the pool to become available.

The ThreadPool is used today by:

  • Automatically by any asynchronous delegate invocation (The BeginInvoke/EndInvoke pattern on a delegate).
  • Internally by the class libraries (HttpWebRequest being one of its major users).
  • Support programs (for example XSP uses the ThreadPool to dispatch incoming requests).
  • The end-user.

A thread does not necessarily have to be executing. The thread can be blocking waiting for I/O to complete, it could be pausing or waiting for a lock to be released. And although it is not actively running, the slot in the threadpool has been taken.

The above conditions can lead to a scenario when one of the four users listed above fills up the ThreadPool and is trying to use other services that also require the ThreadPool, a few scenarios could be:

  • The end user queues all of his work items on the ThreadPool, but the worker code calls into a piece of the class libraries that requires the use of the ThreadPool.
  • XSP uses the ThreadPool to queue requests to handle ASP.NET web requests, and the underlying code internally uses HttpWebRequest, or needs to use the ThreadPool.

In the above scenarios the ThreadPool could be be filled up and when one of the workers attempts to get some work done that requires the ThreadPool the system will deadlock.

Typically users of HttpWebRequest will get a timeout as HttpWebRequest eventually will timeout on the socket connection, so the behavior observed is that requests start to fail with misterious timeouts happening.