套接字异步发送I / O - 没有调用资源泄漏/回调? [英] Socket Async Send I/O - Resource Leak / Callbacks not getting called?

查看:73
本文介绍了套接字异步发送I / O - 没有调用资源泄漏/回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有的问候。


这是一个问题,'过去48小时里我一直在疯狂。

我希望之前有人遇到过这个问题。


我有一个C#应用程序读取UDP广播(异步)。

然后它重新打包这些UDP数据包并发送他们通过TCP获得订户




现在,我可以整天阅读UDP流而无需应用程序

使用更多的内存。一切都得到了''GC''很好。


如果我连接一个用户,并开始通过BeginSend()调度传入的数据包

一切顺利根据计划..暂时。

突然,应用程序内存消耗开始增加......和

我用.NET内存描述了内存Profiler"。

似乎有很多实例叫做

" OverlappedData"累积,我认为它们意味着:

NativeOverlapped。

这些是创建的,但从未被GC收集过。


是..我打电话给'EndSend()"在来自BeginSend()的回调中在

的情况下你想知道。

但是这就是......我已经实现了一个计数器,每个增加

BeginSend()调度和一个计数器,增加每个

EndSend()回调。过了一会儿,我开始看到很小的差异

,在GC开始后不会消失,这表明有几个b
起来很顽皮,没有回电! !


我已经google了所有地方并追查任何有关资源泄漏的参考资料
在.NET下的异步I / O中的
但没有发现任何迹象表明

回调可能会丢失。


我在这里结束了我的智慧。 Hualp!有没有人曾经遇到过类似的东西?b / b
非常感谢提前,


Dennis Richardson


PS:我在Windows Vista(64位)& Windows XP(32-

位),无论如何都没有变化。我确定我做错了什么......但

什么?

解决方案

你能发布一个短但完整的帖子吗?工作示例代码块为

说明你正在做什么导致问题?

Peter


-

网站: http://www.eggheadcafe.com

UnBlog: http://petesbloggerama.blogspot.com

短网址&更多: http://ittyurl.net


" de *************** @ gmx.net"写道:


问候所有。


这是一个问题'过去48年我一直在疯狂小时。

我希望有人之前遇到过这个问题。


我有一个C#应用程序,它读取UDP广播(异步)。 br />
然后它重新打包这些UDP数据包并通过TCP将它们发送给订户




现在,我可以读取UDP流没有应用程序的一整天

使用更多内存。一切都得到了''GC''很好。


如果我连接一个用户,并开始通过BeginSend()调度传入的数据包

一切顺利根据计划..暂时。

突然,应用程序内存消耗开始增加......和

我用.NET内存描述了内存Profiler"。

似乎有很多实例叫做

" OverlappedData"累积,我认为它们意味着:

NativeOverlapped。

这些是创建的,但从未被GC收集过。


是..我打电话给'EndSend()"在来自BeginSend()的回调中在

的情况下你想知道。

但是这就是......我已经实现了一个计数器,每个增加

BeginSend()调度和一个计数器,增加每个

EndSend()回调。过了一会儿,我开始看到很小的差异

,在GC开始后不会消失,这表明有几个b
起来很顽皮,没有回电! !


我已经google了所有地方并追查任何有关资源泄漏的参考资料
在.NET下的异步I / O中的
但没有发现任何迹象表明

回调可能会丢失。


我在这里结束了我的智慧。 Hualp!有没有人曾经遇到过类似的东西?b / b
非常感谢提前,


Dennis Richardson


PS:我在Windows Vista(64位)& Windows XP(32-

位),无论如何都没有变化。我确定我做错了什么......但

什么?


你好丹尼斯,


我在这里结束了我的智慧。 Hualp!有没有人遇到类似的东西?b $ b类似的东西?



是的,非常相似。


但是这就是......我是'我实现了一个计数器,每个BeginSend()调度递增一个
,一个计数器递增每个

EndSend()回调。过了一会儿,我开始看到很小的差异

,在GC开始后不会消失,这表明有几个b
起来很顽皮,没有回电! !



您是否遇到数据丢失,如发送的数据包,但是从未收到过

客户端?

你们将''out Error''对象传递给BeginSend()?它不会改变

结果,但可以提供线索。


我的服务器应用程序通过UDP获取数据,处理它并通过处理
通过TCP向客户提供
数据,与您一样。内存使用率上升到
,直到达到一定限度,然后GC''唤醒''并减少内存量
应用程序使用大约2.5 - 3倍从那一刻开始,在程序开始时保持较低级别的
。它可能需要一个星期才能发生。

我对此非常紧张。我的服务器应用程序几个月无人值守地运行

。由于它们永远不会崩溃,我现在更加自信。不过,我对

..NET 2.0下的异步套接字实现有严重的保留意见。从未调用过的回调只是潜在问题的一半。

另一半是调用回调但是Endxxx()的结果是

一个被处置对象。我从来没有经历过EndSend(),但是使用

EndReceive()它是100%可重复的。


Michael


< de *************** @ gmx.netwrote in message

news:11 ************ *********@n35g2000prd.googlegro ups.com ...


问候所有。


这是一个问题,'过去48小时我一直在疯狂。

我希望有人之前遇到过这个问题。


我有一个C#应用程序读取UDP广播(异步)。

然后它重新打包这些UDP数据包并通过TCP将它们发送给订户




现在,我可以整天阅读UDP流而无需使用更多内存的应用程序

。一切都得到了''GC''很好。


如果我连接一个用户,并开始通过BeginSend()调度传入的数据包

一切顺利根据计划..暂时。

突然,应用程序内存消耗开始增加......和

我用.NET内存描述了内存Profiler"。

似乎有很多实例叫做

" OverlappedData"累积,我认为它们意味着:

NativeOverlapped。

这些是创建的,但从未被GC收集过。


是..我打电话给'EndSend()"在来自BeginSend()的回调中在

的情况下你想知道。

但是这就是......我已经实现了一个计数器,每个增加

BeginSend()调度和一个计数器,增加每个

EndSend()回调。过了一会儿,我开始看到很小的差异

,在GC开始后不会消失,这表明有几个b
起来很顽皮,没有回电! !


我已经google了所有地方并追查任何有关资源泄漏的参考资料
在.NET下的异步I / O中的
但没有发现任何迹象表明

回调可能会丢失。


我在这里结束了我的智慧。 Hualp!有没有人曾经遇到过类似的东西?b / b
非常感谢提前,


Dennis Richardson


PS:我在Windows Vista(64位)& Windows XP(32-

位),无论如何都没有变化。我确定我做错了什么......但是

什么?



" ; Peter Bromberg [C#MVP]"写道:


你能发布一个短但完整的帖子吗?块工作示例代码

说明你正在做什么导致问题?

Peter



你好彼得,


感谢您的回复(以及Michael也是如此)。

不确定一个有效的例子会不会很短,但是这里是基本上是什么

我在做什么:


我们有一个主要的异步读取循环:


public void OnReceive(IAsyncResult IAR)

{

//从套接字读取数据到缓冲区。

//然后调度到TCP套接字BeginSend()

tcpSocket.BeginSend(...回调OnSend);


//队列下一次异步读取

udpSocket .BeginReceiveFrom(...回调到OnReceive);

}


public void OnSend(IAsyncResult)

{

//做EndSend并完成......

}


现在,我已经玩了一些,发现了以下内容:


如果下一个异步接收被延迟,直到调用EndSend回调,

然后问题没有出现。

(换句话说OnReceive - > BeginSend-> OnSend- > BeginReceive-> OnReceive ...等等)

所以不知何故,如果一次只有一个回调活动,那么就没有问题。我认为它可能与ThreadPool线程有关

终止并因此将回调挂起(我看到了一些关于

的故事)。


我做错了什么?


无论如何,有没有人知道如何做一个相当简单的事情,比如

读取UDP套接字并推入一个或多个TCP套接字?难道没有人这样做吗?b $ b有点像我描述的那样吗?


我很乐意提供更多细节,只是不想淹没消息

很多代码。


问候,


Dennis


Greetings all.

Here''s a problem that''s been driving me nuts for the last 48 hours.
I''m hoping that someone has come across this before.

I have a C# Application that reads a UDP broadcast (asynchronously).
Then it repackages these UDP packets and sends them to a subscriber
via TCP.

Now, I can read the UDP stream all day long without the application
ever using more memory. Everything get''s GC''ed just fine.

If I connect a subscriber, and start dispatching the incoming packets
via BeginSend() everything goes according to plan.. for a short while.
Suddenly the application memory consumption starts increasing... and
I''ve profiled the memory with ".NET Memory Profiler".
It seems that there are many instances of something called
"OverlappedData" accumulating, which I think they mean to be:
"NativeOverlapped".
These are created, but never collected by the GC.

Yes.. I am calling "EndSend()" on the callback from "BeginSend()" in
case you are wondering.
But here''s the thing... I''ve implemented a counter that increments
each BeginSend() dispatch and one counter that increments each
EndSend() callback. After a while I start seeing small differences
that do not go away after the GC kicks in, indicating that a few
Begins were naughty and didn''t call back!!

I''ve googled everywhere and chased up any reference on resource leaks
in Async I/O under .NET but found nothing that indicated that
callbacks might get lost.

I''m at the end of my wits here. Hualp!! Has anyone ever encountered
something similar?

Many thanks in advance,

Dennis Richardson

PS: I''ve tried this under Windows Vista (64-bit) & Windows XP (32-
bit), no change whatsoever. I''m sure I''m doing something wrong... but
what?

解决方案

Can you post a "short but complete" block of working sample code to
illustrate what you are doing that''s causing the issue?
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"de***************@gmx.net" wrote:

Greetings all.

Here''s a problem that''s been driving me nuts for the last 48 hours.
I''m hoping that someone has come across this before.

I have a C# Application that reads a UDP broadcast (asynchronously).
Then it repackages these UDP packets and sends them to a subscriber
via TCP.

Now, I can read the UDP stream all day long without the application
ever using more memory. Everything get''s GC''ed just fine.

If I connect a subscriber, and start dispatching the incoming packets
via BeginSend() everything goes according to plan.. for a short while.
Suddenly the application memory consumption starts increasing... and
I''ve profiled the memory with ".NET Memory Profiler".
It seems that there are many instances of something called
"OverlappedData" accumulating, which I think they mean to be:
"NativeOverlapped".
These are created, but never collected by the GC.

Yes.. I am calling "EndSend()" on the callback from "BeginSend()" in
case you are wondering.
But here''s the thing... I''ve implemented a counter that increments
each BeginSend() dispatch and one counter that increments each
EndSend() callback. After a while I start seeing small differences
that do not go away after the GC kicks in, indicating that a few
Begins were naughty and didn''t call back!!

I''ve googled everywhere and chased up any reference on resource leaks
in Async I/O under .NET but found nothing that indicated that
callbacks might get lost.

I''m at the end of my wits here. Hualp!! Has anyone ever encountered
something similar?

Many thanks in advance,

Dennis Richardson

PS: I''ve tried this under Windows Vista (64-bit) & Windows XP (32-
bit), no change whatsoever. I''m sure I''m doing something wrong... but
what?


Hi Dennis,

I''m at the end of my wits here. Hualp!! Has anyone ever encountered
something similar?

yes, quite similar.

But here''s the thing... I''ve implemented a counter that increments
each BeginSend() dispatch and one counter that increments each
EndSend() callback. After a while I start seeing small differences
that do not go away after the GC kicks in, indicating that a few
Begins were naughty and didn''t call back!!

Do you experience data loss like packets sent, but never received by the
client?
Do you pass an ''out Error'' object to BeginSend()? It would not change the
outcome, but could provide a clue.

My server applications get data over UDP, process it and pass processed
data to clients via TCP, same thing as you do. The memory use creeps up
until it reaches a certain limit, then GC ''wakes up'' and reduces the amount
of memory for application use about 2.5 - 3 times and from that moment kept
at lower level then at program start. It may take a week before it happens.
I was quite nervous about this. My server applications run unattended for
several month. Since they never crash I am more confident by now. Still, I
have serious reservations about Asynchronous Sockets implementation under
..NET 2.0. A call back never called is just half of the potential problem.
The other half is when the call back is called but the result of Endxxx() is
a disposed object. I never experienced it with EndSend(), but with
EndReceive() it is 100% reproducible.

Michael

<de***************@gmx.netwrote in message
news:11*********************@n35g2000prd.googlegro ups.com...

Greetings all.

Here''s a problem that''s been driving me nuts for the last 48 hours.
I''m hoping that someone has come across this before.

I have a C# Application that reads a UDP broadcast (asynchronously).
Then it repackages these UDP packets and sends them to a subscriber
via TCP.

Now, I can read the UDP stream all day long without the application
ever using more memory. Everything get''s GC''ed just fine.

If I connect a subscriber, and start dispatching the incoming packets
via BeginSend() everything goes according to plan.. for a short while.
Suddenly the application memory consumption starts increasing... and
I''ve profiled the memory with ".NET Memory Profiler".
It seems that there are many instances of something called
"OverlappedData" accumulating, which I think they mean to be:
"NativeOverlapped".
These are created, but never collected by the GC.

Yes.. I am calling "EndSend()" on the callback from "BeginSend()" in
case you are wondering.
But here''s the thing... I''ve implemented a counter that increments
each BeginSend() dispatch and one counter that increments each
EndSend() callback. After a while I start seeing small differences
that do not go away after the GC kicks in, indicating that a few
Begins were naughty and didn''t call back!!

I''ve googled everywhere and chased up any reference on resource leaks
in Async I/O under .NET but found nothing that indicated that
callbacks might get lost.

I''m at the end of my wits here. Hualp!! Has anyone ever encountered
something similar?

Many thanks in advance,

Dennis Richardson

PS: I''ve tried this under Windows Vista (64-bit) & Windows XP (32-
bit), no change whatsoever. I''m sure I''m doing something wrong... but
what?



"Peter Bromberg [C# MVP]" wrote:

Can you post a "short but complete" block of working sample code to
illustrate what you are doing that''s causing the issue?
Peter

Hello Peter,

Thanks for your response (and Michael too).
Not sure that a working example would be short, but here''s basically what
I''m doing:

We have a main Async read loop:

public void OnReceive(IAsyncResult IAR)
{
// Read the data from the socket into the buffer.
// Then dispatch to TCP socket with BeginSend()
tcpSocket.BeginSend(... callback to OnSend);

// Queue next async read
udpSocket.BeginReceiveFrom(... callback to OnReceive);
}

public void OnSend(IAsyncResult)
{
// Do EndSend and be done...
}

Now, I have played around with it some more and discovered the following:

If the next async receive is delayed until the EndSend Callback was called,
then the problem doesn''t appear.
(in other words OnReceive ->BeginSend->OnSend->BeginReceive->OnReceive... etc)
So somehow, if there is only one callback active at a time, then there is no
problem. I thought that it might have to do with ThreadPool threads
terminating and hence leaving the callbacks hanging (I saw a tidbit about
that somewhere).

Am I doing something wrong?

Anyway, does anyone have an idea of how to do a rather simple thing like
read UDP socket and push into one or more TCP sockets? Wouldn''t one do it
sort of like I described?

I''m happy to provide more details, just don''t want to flood the message with
lots of code.

Regards,

Dennis


这篇关于套接字异步发送I / O - 没有调用资源泄漏/回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆