I am having trouble doing a redirect in an async asp.net implemention.
Most of the time it works, but when it doesn't it just "hangs", the browser
never gets any return page. If I run it under the debugger, it works fine,
though every so often I get a HttpException.
System.Web.HttpException was caught
ErrorCode=-2147024809
Message="An error occurred while communicating with the remote host. The
error code is 0x80070057."
Source="System.Web"
StackTrace:
at
System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6 .FlushCore(Byte[] status,
Byte[] header, Int32 keepConnected, Int32 totalBodySize, Int32
numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32
doneWithSession, Int32 finalStatus, Boolean& async)
at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedR esponse(Boolean
isFinal)
at System.Web.Hosting.ISAPIWorkerRequest.FlushRespons e(Boolean
finalFlush)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpResponse.Flush()
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at w2pagev.PageV.EndPage(IAsyncResult ar) in
G:\inetpub\wwwroot\w2pagev\page.aspx.vb:line 100
The exception is caught in the EndEventHandler.
I am using AddOnPreRenderCompleteAsync to set this up. 12 3437
Hello Pb,
Based on your description, you have an ASP.NET page that is configured as
async execution and it works for most time but will occasionally raise some
error as below, correct?
>>>>>>>>>>>>>>>>>>>
System.Web.HttpException was caught
ErrorCode=-2147024809
Message="An error occurred while communicating with the remote host. The
error code is 0x80070057."
<<<<<<<<<<<<<<<<<<<
So far as I've researched, there hasn't any definite issue of the ASP.NET
2.0 Async page execution. I think the problem here should be application
code logic specific. Would you provide some code logic of your problem
async page, such as what you've done in the async handler, and when you
call the response.Redirect. If possible, you can try simplified it to the
code that is necessary to repro the problem.
In addition, have you checked whether the problem occurs at high stress
condition, such as the application has been stressed under high volume
request execution or will occur even if there is few concurrent requests?
Anyway, please feel free to let me know if you have any other finding or
anything I've missed on this
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
"Steven Cheng[MSFT]" wrote:
Hello Pb,
Based on your description, you have an ASP.NET page that is configured as
async execution and it works for most time but will occasionally raise some
error as below, correct?
>>>>>>>>>>>>>>>>>>
System.Web.HttpException was caught
ErrorCode=-2147024809
Message="An error occurred while communicating with the remote host. The
error code is 0x80070057."
<<<<<<<<<<<<<<<<<<<
So far as I've researched, there hasn't any definite issue of the ASP.NET
2.0 Async page execution. I think the problem here should be application
code logic specific. Would you provide some code logic of your problem
async page, such as what you've done in the async handler, and when you
call the response.Redirect. If possible, you can try simplified it to the
code that is necessary to repro the problem.
In addition, have you checked whether the problem occurs at high stress
condition, such as the application has been stressed under high volume
request execution or will occur even if there is few concurrent requests?
Anyway, please feel free to let me know if you have any other finding or
anything I've missed on this
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
I may have solved my problem, but it’s hard to know with intermittent
problems like this… so let me better describe it:
The async model is hooked up like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim bh As New BeginEventHandler(AddressOf Me.BeginPage)
Dim eh As New EndEventHandler(AddressOf Me.EndPage)
Me.AddOnPreRenderCompleteAsync(bh, eh)
End Sub
Function BeginPage(ByVal src As Object, ByVal args As EventArgs, ByVal cb As
AsyncCallback, ByVal state As Object) As IAsyncResult
Trace.Write("BeginPage: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)
Dim v As New vmstate
v.m_page = Me
v.m_config = m_config
Dim vrs As New viewmanagerstate(Context, cb, v)
m_vm = New viewmanager(vrs)
Dim ts As New ThreadStart(AddressOf m_vm.start)
Dim thread As New Thread(ts)
thread.Start()
Return vrs
End Function
Sub EndPage(ByVal ar As IAsyncResult)
Try
Trace.Write("EndPage: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)
Dim m_vrs As viewmanagerstate = CType(ar, viewmanagerstate)
If Not IsNothing(m_vrs.m_data.m_redirect) Then
m_redirect = m_vrs.m_data.m_redirect
'Response.Redirect(m_vrs.m_data.m_redirect, True)
End If
Catch ex As Exception
End Try
End Sub
Protected Overrides Sub OnPreRenderComplete(ByVal e As System.EventArgs)
MyBase.OnPreRenderComplete(e)
Try
Trace.Write("OnPreRenderComplete: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)
If Not IsNothing(m_redirect) Then
Response.Redirect(m_redirect, True)
End If
Catch ex As Exception
End Try
End Sub
For now, I left out the details of viewmanagerstate, but it is a class that
implements IAsyncResult.
So in begin, I spin off a new thread. This is NOT a thread pool thread
(which of course is the whole point).
So the trouble occurs if I use Response.Redirect from EndPage. This will be
in my new thread’s context and perhaps that’s the problem right there, the
Response.Redirect with TRUE will abort the thread (I think). After posting,
I moved the Redirect to OnPreRenderComplete, where we are back on a thread
pool thread.
It seems to work there; I have tested it and can’t get it to break as
before, but I am concerned that the problem is just less likely in this
context vs. fixed. It would be great to confirm from MSFT that the
Response.Redirect in EndPage will not work and moving it to
OnPreRenderComplete is the way to go.
I can provide more details of my implementation if it would help.
"pb" <pb@newsgroups.nospamwrote in message
news:1B**********************************@microsof t.com...
"Steven Cheng[MSFT]" wrote:
The async model is hooked up like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim bh As New BeginEventHandler(AddressOf Me.BeginPage)
Dim eh As New EndEventHandler(AddressOf Me.EndPage)
Me.AddOnPreRenderCompleteAsync(bh, eh)
End Sub
Function BeginPage(ByVal src As Object, ByVal args As EventArgs, ByVal cb
As
AsyncCallback, ByVal state As Object) As IAsyncResult
Trace.Write("BeginPage: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)
Dim v As New vmstate
v.m_page = Me
v.m_config = m_config
Dim vrs As New viewmanagerstate(Context, cb, v)
m_vm = New viewmanager(vrs)
Dim ts As New ThreadStart(AddressOf m_vm.start)
Dim thread As New Thread(ts)
thread.Start()
Maybe it's in the code you didn't include, but I don't see what keeps your
page from completing the request before your thread even begins executing.
This will cause your thread to be referenceing a page which is in an invalid
state. Perhaps it's your thread that caused the EndPage to be called?
You are creating a major maintenance headache for yourself with this code.
There is a reason why you don't see many examples of ASP.NET code that
creates another thread. It's not meant to work that way.
John
"John Saunders" wrote:
"pb" <pb@newsgroups.nospamwrote in message
news:1B**********************************@microsof t.com...
"Steven Cheng[MSFT]" wrote:
The async model is hooked up like this:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim bh As New BeginEventHandler(AddressOf Me.BeginPage)
Dim eh As New EndEventHandler(AddressOf Me.EndPage)
Me.AddOnPreRenderCompleteAsync(bh, eh)
End Sub
Function BeginPage(ByVal src As Object, ByVal args As EventArgs, ByVal cb
As
AsyncCallback, ByVal state As Object) As IAsyncResult
Trace.Write("BeginPage: Thread #" &
System.Threading.Thread.CurrentThread.GetHashCode( ) & "; " &
System.Threading.Thread.CurrentThread.IsThreadPool Thread)
Dim v As New vmstate
v.m_page = Me
v.m_config = m_config
Dim vrs As New viewmanagerstate(Context, cb, v)
m_vm = New viewmanager(vrs)
Dim ts As New ThreadStart(AddressOf m_vm.start)
Dim thread As New Thread(ts)
thread.Start()
Maybe it's in the code you didn't include, but I don't see what keeps your
page from completing the request before your thread even begins executing.
This will cause your thread to be referenceing a page which is in an invalid
state. Perhaps it's your thread that caused the EndPage to be called?
You are creating a major maintenance headache for yourself with this code.
There is a reason why you don't see many examples of ASP.NET code that
creates another thread. It's not meant to work that way.
John
John,
thanks for the reply, but i don't understand your points.
AddOnPreRenderCompleteAsync is setup by MSFT for async pages. ASP.NET keeps
the page from completing by ensuring BeginPage is called in the chain. then,
yes, my thread callsback to EndPage.
there is no reason i can't spin up a thread here. see http://msdn.microsoft.com/msdnmag/is...10/WickedCode/ for more
information.
Thanks for your followup Pb,
After got the code snippet you provided, I notice that your implementation
is quite different as I expect. Yes, you haven't simply used the existing
async components (like delegate or WebRequest...) and manually create a
normal sub thread to do the work.
And in addition to the "IAsyncResult" implmentation class, another thing
you haven't provided is your thread proc function. You need to ensure the
passed in callback should be invoked at the end of your thread proc
function(when the task has finished). Also, I think the occasional hang
problem does be possible related to the IAsyncResult implementation. You
can try using Delegate.BeginInvoke approach to run the same stuff to see
whether it will lead to the same behvior.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
"Steven Cheng[MSFT]" wrote:
Thanks for your followup Pb,
After got the code snippet you provided, I notice that your implementation
is quite different as I expect. Yes, you haven't simply used the existing
async components (like delegate or WebRequest...) and manually create a
normal sub thread to do the work.
And in addition to the "IAsyncResult" implmentation class, another thing
you haven't provided is your thread proc function. You need to ensure the
passed in callback should be invoked at the end of your thread proc
function(when the task has finished). Also, I think the occasional hang
problem does be possible related to the IAsyncResult implementation. You
can try using Delegate.BeginInvoke approach to run the same stuff to see
whether it will lead to the same behvior.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Steven-
a couple of things... i don't think i am having any more trouble with the
redirect now that i've moved it (see previous code). i do, however,
experience "hangs" when running the new thread model under load (using WCAT).
over the course of several hours, i will see ASP.NET restart several times
when it failed to respond to the IIS ping. i do not experience these hangs
when i switch to my old implementation (i have a simple switch that runs it
async or not).
i too suspect it might be the iasyncresult implemention, and i will test
under a simple async delegate model to try to isolate it. in the mean time,
here is my iasynresult implementation:
Public Class viewmanagerstate
Implements IAsyncResult
Public m_context As HttpContext
Public m_cb As AsyncCallback
Public m_data As vmstate
Public m_iscompleted As Boolean = False
Public m_callcompleteevent As ManualResetEvent = Nothing
Public Sub New(ByVal context As HttpContext, ByVal cb As AsyncCallback,
ByVal data As Object)
m_context = context
m_cb = cb
m_data = data
End Sub
Public ReadOnly Property AsyncState() As Object Implements
System.IAsyncResult.AsyncState
Get
Return m_data
End Get
End Property
Public ReadOnly Property AsyncWaitHandle() As
System.Threading.WaitHandle Implements System.IAsyncResult.AsyncWaitHandle
Get
SyncLock Me
If IsNothing(m_callcompleteevent) Then
m_callcompleteevent = New ManualResetEvent(False)
End If
End SyncLock
Return m_callcompleteevent
End Get
End Property
Public ReadOnly Property CompletedSynchronously() As Boolean Implements
System.IAsyncResult.CompletedSynchronously
Get
Return False
End Get
End Property
Public ReadOnly Property IsCompleted() As Boolean Implements
System.IAsyncResult.IsCompleted
Get
Return m_iscompleted
End Get
End Property
Public Sub CompleteRequest()
m_iscompleted = True
SyncLock Me
If Not IsNothing(m_callcompleteevent) Then
m_callcompleteevent.Set()
End If
End SyncLock
m_cb.Invoke(Me)
End Sub
End Class
"pb" <pb@newsgroups.nospamwrote in message
news:46**********************************@microsof t.com...
>
....
"John Saunders" wrote:
>Maybe it's in the code you didn't include, but I don't see what keeps your page from completing the request before your thread even begins executing. This will cause your thread to be referenceing a page which is in an invalid state. Perhaps it's your thread that caused the EndPage to be called?
You are creating a major maintenance headache for yourself with this code. There is a reason why you don't see many examples of ASP.NET code that creates another thread. It's not meant to work that way.
John
John,
thanks for the reply, but i don't understand your points.
AddOnPreRenderCompleteAsync is setup by MSFT for async pages. ASP.NET
keeps
the page from completing by ensuring BeginPage is called in the chain.
then,
yes, my thread callsback to EndPage.
As I said above, "maybe it's in the code you didn't include". If the
completion of your thread is the only way for EndPage to be called, then you
won't have the issue I was concerned with, as the page will not complete
before your thread is through with it.
In general, this technique should work, at least until you can no longer
create new threads.
John
"pb" <pb@newsgroups.nospamwrote in message
news:3A**********************************@microsof t.com...
>
"Steven Cheng[MSFT]" wrote:
>Thanks for your followup Pb,
After got the code snippet you provided, I notice that your implementation is quite different as I expect. Yes, you haven't simply used the existing async components (like delegate or WebRequest...) and manually create a normal sub thread to do the work.
And in addition to the "IAsyncResult" implmentation class, another thing you haven't provided is your thread proc function. You need to ensure the passed in callback should be invoked at the end of your thread proc function(when the task has finished). Also, I think the occasional hang problem does be possible related to the IAsyncResult implementation. You can try using Delegate.BeginInvoke approach to run the same stuff to see whether it will lead to the same behvior.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Steven-
a couple of things... i don't think i am having any more trouble with the
redirect now that i've moved it (see previous code). i do, however,
experience "hangs" when running the new thread model under load (using
WCAT).
over the course of several hours, i will see ASP.NET restart several times
when it failed to respond to the IIS ping. i do not experience these hangs
when i switch to my old implementation (i have a simple switch that runs
it
async or not).
Make very certain that you have a try/catch block around all of your
threads. Otherwise, an unhandled exception will just quietly kill the
thread.
John
"Steven Cheng[MSFT]" wrote:
Thanks for your followup Pb,
After got the code snippet you provided, I notice that your implementation
is quite different as I expect. Yes, you haven't simply used the existing
async components (like delegate or WebRequest...) and manually create a
normal sub thread to do the work.
And in addition to the "IAsyncResult" implmentation class, another thing
you haven't provided is your thread proc function. You need to ensure the
passed in callback should be invoked at the end of your thread proc
function(when the task has finished). Also, I think the occasional hang
problem does be possible related to the IAsyncResult implementation. You
can try using Delegate.BeginInvoke approach to run the same stuff to see
whether it will lead to the same behvior.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Steven--
at your suggestion, i tried a simple async delegate model. it works; i ran
it through an overnight test and ASP.NET never restarted. so i pretty much
believe that its either my iasyncresult implementation or under my
iasyncresult implementation the code is stressed in another way that causes
it to break. if you could look over my iasyncresult implementation, it would
be much appreciated (its in the previous post).
/phil
On Feb 23, 10:48 am, "John Saunders" <john.saunders at trizetto.com>
wrote:
"pb" <p...@newsgroups.nospamwrote in message
news:3A**********************************@microsof t.com...
"Steven Cheng[MSFT]" wrote:
Thanks for your followup Pb,
After got the code snippet you provided, I notice that your
implementation
is quite different as I expect. Yes, you haven't simply used the existing asynccomponents (like delegate or WebRequest...) and manually create a
normal sub thread to do the work.
And in addition to the "IAsyncResult" implmentation class, another thing
you haven't provided is your thread proc function. You need to ensure
the
passed in callback should be invoked at the end of your thread proc
function(when the task has finished). Also, I think the occasional hang
problem does be possible related to the IAsyncResult implementation. You
can try using Delegate.BeginInvoke approach to run the same stuff to see
whether it will lead to the same behvior.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.
Steven-
a couple of things... i don't think i am having any more trouble with the
redirectnow that i've moved it (see previous code). i do, however,
experience "hangs" when running the new thread model under load (using
WCAT).
over the course of several hours, i will see ASP.NET restart several times
when it failed to respond to the IIS ping. i do not experience these hangs
when i switch to my old implementation (i have a simple switch that runs
it
asyncor not).
Make very certain that you have a try/catch block around all of your
threads. Otherwise, an unhandled exception will just quietly kill the
thread.
John- Hide quoted text -
- Show quoted text -
john,
that's an important point. if an exception aborts the thread before
it completes EndPage won't be called. what does ASP.NET do in that
case? does it just time out the initial thread that dispatched the
page (the CLR thread pool thread)? i imagine, even if it timed out
the dispatch thread that all the thread pool threads could be consumed
in this case and then ASP.NET would "hang"... and IIS would be forced
to restart it. i will make certain my thread always completes to the
caller regardless of what is does in between!
/phil
Thanks for your reply Pb,
I'll have a further check and test based on the code you provided. I'll
update you as soon as possible.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Pb,
Sorry for the dely update. After some further research, I still haven't
been able to address the root cause of the issue. The difficulty here is
that the behavior is quite hard to test in development, and the underlying
cause require some low level debugging. After discussing with some other
engineers, we suggest you consider contact CSS for further troubleshooting
on this issue: http://msdn.microsoft.com/subscripti...t/default.aspx
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: PaulThomas |
last post by:
I am fighting with XP-Pro and VS.Net trying to allow some of the pages in my
application to be accessable by 'all' I am using <authentication
mode="Forms" /> and if I Login - everything works...
|
by: Vanessa |
last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object.
Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work
again after half an hour or so without doing...
|
by: Bob Johnson |
last post by:
Hello people.
Short background -- I am constructing a web site that will have several
display tabs that are hooked up to different datatables in a SQL server.
Some of these tables are VERY large...
|
by: Homa |
last post by:
Hi all,
Can anyone give me some links about how to do an async web service call
from aspx and display a temperary page before the web service returns?
Thanks,
Homa Wong
|
by: Leneise44 |
last post by:
Does the new async features within asp.net 2.0 and ado.net 2.0 render the
async application block (1.1) extinct? What would be the advantages of using
the async application block with 2.0? Seems...
|
by: jonathan |
last post by:
I need to create a webpage that asynchronously loads a series of user
controls onto a page.
If the user control take longer than X seconds to load it should
display an error message in it place....
|
by: =?Utf-8?B?YzY3NjIyOA==?= |
last post by:
Hi all,
We have two sites hosted on different servers and we have many pages on
domain A which has many links(asp programs) to domain B.
My question is if domain B server is in trouble, what is...
|
by: robert112 |
last post by:
Question... Can one not use ThreadPool.QueueUserWorkItem with an
anonymous method like so:
ThreadPool.QueueUserWorkItem(delegate
{
//perform IO bound operation.
});
Why did the asp.net team...
|
by: Norm |
last post by:
The error that pops up in a JS alert box is:
Sys.WebForms.PageRequestManagerParserErrorException: The message from
the server could not be parsed. ... "<DOCTYPE ..."
I have three update panels...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |