Results 1 to 2 of 2

Thread: [RESOLVED] Latest MS Update - changed http.sys - and now I'm getting strange behavior

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [RESOLVED] Latest MS Update - changed http.sys - and now I'm getting strange behavior

    Ok - been working for a long time on an app - working a backend service. When I debug this app it starts 4 services in the IDE and they all talk via http to each other. This has been working great for 12 months now.

    Upon getting the latest release of MS updates - which included lots of changes to http.sys - this code below stopped working as expected. It works 4 out of 5 times - but sometimes blows up.

    In the FINALLY - where I check to see if the response isnot nothing - I go to close the response and get an error of:

    Code:
                Finally
                    If response IsNot Nothing Then
                        response.Close()
                    End If
                End Try
    "An operation was attempted on a nonexistent network connection". What is the proper way to see if the response needs to be closed? I've attached an image of the RESPONSE object on a watch window.

    And why is it all of a sudden behaving this way. The packets are all still flowing as expected - the program still runs as expected from what I see. It's just this clean-up code not awlays working the same way.

    Code:
                Dim response As HttpListenerResponse = Nothing
                Try
                    If cl2.responseStart(request, FSOb, returnMessage) Then
                        With FSOb
                            Try
                                Using dcn As New SqlConnection(m_ConnStr)
                                    Using cmd As New SqlCommand
                                        cmd.CommandType = CommandType.StoredProcedure
                                        cmd.CommandText = "Discovery_Load" ' "TagInfo_Load"
                                        cmd.Connection = dcn
                                        cmd.Parameters.AddWithValue("@GCId", .FileId)
    .
    .
    .
                                        cmd.Parameters.AddWithValue("@TagInfo", strTI)
                                        dcn.Open()
                                        Dim strMessage As String = cmd.ExecuteScalar.ToString
                                    End Using
                                End Using
                            Catch ex As Exception
                                'MessageBox.Show(ex.Message, "Archive Discovery_Load")
                            End Try
                        End With
    .
    .
    .
                        rtnSize = cl2.responseEnd(response, context, FSOb, returnMessage)
                    End If
                Catch ex As Exception
                    returnMessage = ex.Message
                Finally
                    If response IsNot Nothing Then
                        response.Close()
                    End If
                End Try
    cl2.responseStart looks like this

    Code:
        Public Function responseStart(ByRef request As HttpListenerRequest, ByRef FSOb As FSObject, ByRef TraceMsg As String) As Boolean
            Dim blnSuccess As Boolean = True
            TraceMsg = ""
            Try
                Dim inputstream As Stream = request.InputStream()
                Deserialize(FSOb, inputstream)
                'FSOb.AffectCnt()
                TraceMsg = FSOb.DesiredAction
                If FSOb.FileId = 0 Then
                    TraceMsg = "%Index " & FSOb.FileIndex.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Rcvd " & CInt((request.ContentLength64 + 1024) / 1024).ToString & " KB)"
                Else
                    TraceMsg = "F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Rcvd " & CInt((request.ContentLength64 + 1024) / 1024).ToString & " KB)" & tagList(FSOb)
                End If
                'If request.UserAgent = "search" Then
                If request.Headers("x-package") = "search" Then
                    If FSOb.DesiredAction = "space" Then
                        TraceMsg &= " search/space=" & FSOb.FNTagsCollection(0)
                    ElseIf FSOb.DesiredAction = "enter" Then
                        TraceMsg &= " search/enter=" & FSOb.FNTagsCollection(0)
                    Else
                        TraceMsg &= " search=" & FSOb.FNTagsCollection(0)
                    End If
                End If
                'If request.UserAgent = "searchdone" Then TraceMsg &= " narrowresult=" & FSOb.FNTagsCollection(0)
            Catch ex As HttpListenerException
                TraceMsg = ex.Message
                blnSuccess = False
            Catch ex As Exception
                TraceMsg = ex.Message
                blnSuccess = False
            End Try
            TraceMsg = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString.PadLeft(2, "0"c) & " S)  " & TraceMsg
            Return blnSuccess
        End Function
    and cl2.responseEnd looks like this

    Code:
        Public Function responseEnd(ByRef response As HttpListenerResponse, ByRef context As HttpListenerContext, ByRef FSOb As FSObject, ByRef TraceMsg As String) As Long
            Dim rtnSize As Long = 0
            TraceMsg = ""
            Try
                'FSOb.AffectCnt()
                response = context.Response
                Dim output As System.IO.Stream = response.OutputStream
                Using fsMS As New MemoryStream
                    Serialize(FSOb, fsMS)
                    output.Write(fsMS.ToArray, 0, CInt(fsMS.Length))
                    rtnSize = fsMS.Length
                    If FSOb.ReaderRegistered Then
                        TraceMsg = FSOb.SessionId.ToString & ">F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Send " & CInt((fsMS.Length + 1024) / 1024).ToString & " KB)" & tagList(FSOb)
                    Else
                        TraceMsg = FSOb.SessionId.ToString & ">F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Send " & CInt((fsMS.Length + 1024) / 1024).ToString & " KB)"
                    End If
                End Using
            Catch ex As HttpListenerException
                TraceMsg = ex.Message
            Catch ex As Exception
                TraceMsg = ex.Message
            End Try
            TraceMsg = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString.PadLeft(2, "0"c) & " E)  " & TraceMsg
            Return rtnSize
        End Function
    Attached Images Attached Images  

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Latest MS Update - changed http.sys - and now I'm getting strange behavior

    Found my problem - missing "output.Close()" in this function.

    Code:
        Public Function responseEnd(ByRef response As HttpListenerResponse, ByRef context As HttpListenerContext, ByRef FSOb As FSObject, ByRef TraceMsg As String) As Long
            Dim rtnSize As Long = 0
            TraceMsg = ""
            Try
                'FSOb.AffectCnt()
                response = context.Response
                Dim output As System.IO.Stream = response.OutputStream
                Using fsMS As New MemoryStream
                    Serialize(FSOb, fsMS)
                    output.Write(fsMS.ToArray, 0, CInt(fsMS.Length))
                    output.Close()
                    rtnSize = fsMS.Length
                    If FSOb.ReaderRegistered Then
                        TraceMsg = FSOb.SessionId.ToString & ">F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Send " & CInt((fsMS.Length + 1024) / 1024).ToString & " KB)" & tagList(FSOb)
                    Else
                        TraceMsg = FSOb.SessionId.ToString & ">F" & FSOb.FileId.ToString & " " & FSOb.DesiredAction & " " & FSOb.WhoFrom & " (Send " & CInt((fsMS.Length + 1024) / 1024).ToString & " KB)"
                    End If
                End Using
            Catch ex As HttpListenerException
                TraceMsg = ex.Message
            Catch ex As Exception
                TraceMsg = ex.Message
            End Try
            TraceMsg = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString.PadLeft(2, "0"c) & " E)  " & TraceMsg
            Return rtnSize
        End Function

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width